Stone GameProblem code: RESN04 |
All submissions for this problem are available.
Alice and Bob play the following game : There are N piles of stones with Si stones in the ith pile. Piles are numbered from 1 to N. Alice and Bob play alternately, with Alice starting. In a turn, the player chooses any pile i which has atleast i stones in it, and removes exactly i stones from it. The game ends when there is no such pile. The player who plays last wins the game. Assuming Alice and Bob play optimally, who will win the game?
Input
The first line contains the number of test cases T (<= 100). There follow 2T lines, 2 per test case. The first line of each test case conains N (<= 100), the number of piles. The second line contains N space seperated integers, specifying the number of stones in pile 1, pile 2, ..., pile N. There will be atleast 1 and atmost 1000 stones in any pile.
Output
Output T lines, one per test case. For each test case, output "ALICE" if Alice wins the game, and "BOB" if Bob wins the game.
Example
Input: 2 1 1 2 1 1 Output: ALICE ALICE
| Author: | admin |
| Date Added: | 18-12-2009 |
| Time Limit: | 5 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
|
If you are still having problems, see a sample solution here. |

Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
I think my code is giving the
I think my code is giving the right answer, I don't know why CodeChef is showing Wrong Answer. Here is my code:
#include<stdio.h>
#include<stdlib.h>
int stones[100] = {0};
int main()
{
int test, i, piles, count;
scanf("%d", &test);
while(test--)
{
count = 0;
scanf("%d", &piles);
for(i=0;i<piles;i++)
scanf("%d", &stones[i]);
for(i=0;i<piles;i++)
{//number of stones will be zero after S turns, cuz Si stones in each pile
count = count + stones[i]/(i+1);
}//for ends
if(count%2==0)
printf("BOB");
else printf("ALICE");
}//while ends
return 0;
}//main ends
you are not printing end of
you are not printing end of line n.
can someone check this out
can someone check this out and lemme know my mistake?
http://www.codechef.com/viewsolution/273267
Your code gives the wrong
Your code gives the wrong output for the sample input.
Can any body please explain
Can any body please explain the logic.
#include<stdio.h>#include<std
#include<stdio.h>
#include<stdlib.h>
int stones[100] = {0};
int main()
{
int test, i, piles, count;
scanf("%d", &test);
while(test--)
{
count = 0;
scanf("%d", &piles);
for(i=0;i<piles;i++)
scanf("%d", &stones[i]);
for(i=0;i<piles;i++)
{//number of stones will be zero after S turns, cuz Si stones in each pile
count = count + stones[i]/(i+1);
}//for ends
if(count%2==0)
printf("BOBn");
else printf("ALICEn");
}//while ends
return 0;
}//main ends
wat does playing optimally
wat does playing optimally mean????????
guys...wat does optimal means
guys...wat does optimal means ??
http://dictionary.reference.c
http://dictionary.reference.com/browse/optimal
hi friends below programme
hi friends below programme was giving the correct output for th input can any one please tell me why it is wrong
#include <stdio.h>
#include <stdlib.h>
int main()
{
int no_of_piles,*stones_in_piles,counter1,counter2;
int player,first_chance,no_of_testcases;
int *winner;
scanf("%d",&no_of_testcases);
winner = (int *)malloc(sizeof(int) * no_of_testcases);
for(counter2=0;counter2<no_of_testcases;counter2++)
{
player = 1;//1 = Alice , 0 = Bob
first_chance = 1;
scanf("n%d",&no_of_piles);
stones_in_piles = (int *)malloc(sizeof(int) * no_of_piles);
for(counter1=0;counter1<no_of_piles;counter1++)
{
scanf("%d",&stones_in_piles[counter1]);
}
while(1)
{
for(counter1=0;counter1<no_of_piles;counter1++)
{
if(stones_in_piles[counter1]>=(counter1+1))
{
stones_in_piles[counter1]=stones_in_piles[counter1]-(counter1+1);
if(player)
player = 0;
else
player = 1;
first_chance = 0;
break;
}
}
if(counter1 == no_of_piles)
{
if(first_chance)
{
printf("nNo one wins as no piles sufficient to play");
free(stones_in_piles);
break;
}
if(player)
player = 0;
else
player = 1;
winner[counter2]=player;
free(stones_in_piles);
break;
}
}
}
for(counter2=0;counter2<no_of_testcases;counter2++)
{
if(winner[counter2])
printf("Alicen");
else
printf("Bobn");
}
free(winner);
}
i got it right actually
i got it right actually earlier it was wrong because i printed Alice and Bob in Sentence case and not in upper case
Thanks a lot
I din't understood the
I din't understood the problem, is too complicated for me.
Can anyone tell why this code
sorry i have not used
sorry i have not used #include<conio.h> and getch() in my submission .It is giving wrong answer.
Where do you initialise the
Where do you initialise the values of num?
some one please tell me
some one please tell me what's the problem with my code?
it's running fine on my computer but when i submit it ,codechef indicates runtime error.
http://www.codechef.com/comment/reply/498643
Here's my code.It's simple
Here's my code.It's simple enough.but i am not able to figure out any flaw in it.I will be pleased to get a feedback from you.
#include<stdio.h>
#include<malloc.h>
int main()
{
int T,N,*stones,i,j,count=0;
char* str;
scanf("%d",&T);
str=(char *)calloc(T,sizeof(char));
for(i=0;i<T;i++)
{
scanf("%d",&N);
stones=(int*)calloc(N,sizeof(int));
for(j=0;j<N;j++)
{
scanf("%d",&stones[j]);
}
for(j=0;j<N;j++)
{
if(stones[j]>=j+1)
count++;
}
if(count%2==0)
str[i]='B';
else
str[i]='A';
count=0;
}
for(i=0;i<T;i++)
{
if(str[i]=='B')
printf("BOBn");
else
printf("ALICEn");
}
}
I want the codechef team to
I want the codechef team to clarify their output pattern.
I tried submitting my code for an hour and finally was able to catch the mistake that i used printf command after all the test cases to print either ALICE or BOB for each test case.
I don't think this thing is clear in the problem.Hope my this comment helps someone and improves the clarification of output pattern in furthur problems.
It makes no difference
It makes no difference whatsoever at what point during your program you print output. This is clearly mentioned in the FAQ.
You were getting a runtime error because your main function wasn't returning 0. That is also clearly mentioned in the FAQ.
Your wrong answers were because you were outputting the wrong answers.
@Stephen: Sorry to bother
If the last pile has at least
If the last pile has at least n stones you seem to ignore every other pile entirely. That can't be right.
@Stephen: I don't think I
@Stephen: I don't think I ever said thanks so many times to a person!!
Thank you so much!
It was a blunder!
#include<stdio.h> int
#include<stdio.h>
int main()
{
int a[100],stone[100]={0},c[100]={0},n,i,j,k=0,pile;
printf("enter the number of test cases:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&pile);
for(j=0;j<pile;j++)
scanf("%d",&stone[j]);
for(j=0;j<pile;j++)
c[k]=c[k]+stone[j];
k++;
}
for(j=0;j<n;j++)
{
if((c[j])%2==0)
printf("BOBn");
else
printf("ALICEn");
}
for(j=0;j<100;j++)
c[j]=0;
return 0;
}
@stephen sir:what is wrong in this code ???
#include<stdio.h>int main(){
#include<stdio.h>
int main()
{
int i,s,t,n,u;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
u=0;
for(i=1;i<=n;i++)
{
scanf("%d",&s);
u^=s/i&1;
}
if (u)
printf("ALICEn");
else
printf("BOBn");
}
return 0;
}
This was one of the solution given in all solutions for this problem.
But for the following input
1
3
1 2 3
Output
ALICE
But BOB can always win the game if he plays optimally.
Am i correct ?
No.
No.
IT IS UNFORTUNATE THAT "ALICE
IT IS UNFORTUNATE THAT "ALICE " INSTEAD OF "Alice" IS GIVING WRONG ANSWER; ADMIN:PLEASE TAKE CARE OF IT........
There's nothing to take care
There's nothing to take care of. If you don't do what the problem statement clearly tells you to do, you will get wrong answer.
@meriam:could you please
@meriam:could you please explain the logic behind this kind of solutions???
#include<stdio.h>
int main()
{
int a[100],stone[100]={0},c[100]={0},n,i,j,k=0,pile;
printf("enter the number of test cases:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&pile);
for(j=0;j<pile;j++)
scanf("%d",&stone[j]);
for(j=0;j<pile;j++)
c[k]=c[k]+stone[j];
k++;
}
for(j=0;j<n;j++)
{
if((c[j])%2==0)
printf("BOBn");
else
printf("ALICEn");
}
admin could u plz teme y m i
admin could u plz teme y m i gettin wrong answer for my submitted code? kindly check my submission
Code runs on my machine with
Code runs on my machine with the Python Interpreter but CodeChef says there's a runtime error.. Why?
Use Python3
Have a look:
#!/usr/bin/env python
T = eval(input(""))
for case in range(0,T):
N = eval(input(""))
turns = 0
inp = input("")
stones = inp.split(None)
for pile in range(0,N):
if eval(stones[pile])>pile:
turns = turns + (eval(stones[pile])/(pile+1))
if turns % 2 == 0:
print("BOB")
else:
print("ALICE")
my code has been accepted
Hello. Can somebody plz
hey there is a problem in
@admin Where's the problem in
http://www.codechef.com/views
FAQ said that output file
I had a NZEC error in java .I
what if there are no such
import
please tell why the following
It says that game start with
@ujjwal The printf statements
Can anyone tell me how this
what is the problem with this
&ADMIN perhaps your compiler
My code is giving a run time
Hi i have a question ..! For
Hi babbarshaer,
sagarchak @ u r substracting
http://www.codechef.com/views
Could someone tell me what is
Hey i submitted my code and