616  Coconuts, Revisited
Moderator: Board moderators
616
Why I get "Wrong Answer"? Have anyone help me.
Code: Select all
#include<stdio.h>
#include<math.h>
main()
{
float coconuts;
unsigned long temp_c,ok,i,j,max_people;
while(scanf(" %f",&coconuts)){
if(coconuts<0) break;
temp_c=coconuts; ok=0;
max_people=(unsigned)pow(coconuts,0.5)+2;
for(i=max_people;i>1;i){
temp_c=coconuts;
for(j=i;j>0;j){
if((temp_c1)%i==0){
temp_c=temp_c(temp_c1)/i1;
ok=1;
}
else{
ok=0;
break;
}
}
if(ok){
printf("%.0f coconuts, %lu people and 1 monkey\n",coconuts,i);
break;
}
}
if(!ok)
printf("%.0f coconuts, no solution\n",coconuts);
}
}
how did you come up with the upper bound? that is always my problem with this type of problem (ugh...)kmhasan wrote:simulate in range sqrt(coconuts)+1 down to 2.
i tried from coconuts down to 2 and TLE.... so i tried coconuts/2 as upperbound..... still not (although it did not know why....)
anyone can help?
thanks
guilherme

 New poster
 Posts: 45
 Joined: Fri Jan 16, 2004 7:02 pm
 Location: CSE::BUET
 Contact:
616
Hey guys, I just got AC after a WA. I thought I'd share a couple of strange things about the problem:
1. Input is terminated with a negative number. You must process 0s.
2. Special case:
Say in the morning there are no coconuts left. The description says that the coconuts left in the morning are divided between all the people and this time there is none left over. Now, look at the following:
Logically, this is not a good solution. I think it should be "no solution" in this case. But I thought it might be like this and submitted the problem resulting in an WA. I just took out one condition and got AC. These things are frustrating, I know. That's what this post is for....
1. Input is terminated with a negative number. You must process 0s.
2. Special case:
Say in the morning there are no coconuts left. The description says that the coconuts left in the morning are divided between all the people and this time there is none left over. Now, look at the following:
Code: Select all
No. of coconuts: 3
No. of people: 2
The first guy wakes up, divides the 3 coconuts into two piles and gives the remaining coconut to the monkey. So, there's only 1 coconut left when the second guy wakes up. He divides the 1 coconut into 2 piles and gives the remaining coconut to the monkey. So there are 0 coconuts left in the morning. In the morning these 0 coconut/s are divided between the 2 people with each person getting 0 coconut/s.
We will, We will BREAK LOOP!!!!
616: Coconuts, revisited
Hi, what is the output for 1 and 0? Should it be "1 coconut, no solution" or "1 coconuts, no solution"?
Anyway, could anyone give the output for the following numbers?
0
1
2
3
7
253
509
65529
16777209
Thanks in advance!
Javi
Anyway, could anyone give the output for the following numbers?
0
1
2
3
7
253
509
65529
16777209
Thanks in advance!
Javi

 New poster
 Posts: 8
 Joined: Fri May 20, 2005 5:53 pm

 New poster
 Posts: 33
 Joined: Tue Jun 29, 2004 1:38 pm
 Location: IITM,chennai,Tamil Nadu,India
 Contact:
616 WA
Someone help me please....Dunno why i get WA for this code
Code: Select all
removed after getting ac
Last edited by Karthekeyan on Thu Dec 29, 2005 8:31 am, edited 1 time in total.
Karthe
Test the i/o set...
Input:
Output:
Hope it works.
Input:
Code: Select all
24
36
74
1
Code: Select all
24 coconuts, no solution
36 coconuts, no solution
74 coconuts, no solution
Ami ekhono shopno dekhi...
HomePage
HomePage

 New poster
 Posts: 33
 Joined: Tue Jun 29, 2004 1:38 pm
 Location: IITM,chennai,Tamil Nadu,India
 Contact:
616 WA ...help!
I don't know why do I got WA!?
Please give me some input and output data to test my program.
Or help me to find the mistake.....Please
Thanks in advance...
Please give me some input and output data to test my program.
Or help me to find the mistake.....Please
Thanks in advance...
Code: Select all
I find my mistake and got Acc...Thanks!

 New poster
 Posts: 7
 Joined: Fri Mar 31, 2006 1:22 pm
Because you have to check the result can be divide by people.
For example, 25.
(251)/3=8
so after first person, still 16 coconuts left.
(161)/3=5
so after second person, still 10 coconuts left.
and after third person, 6 coconuts left. > result
AND,
6 can be divide by 3, so 3 people is right.
if the result can not divide by 3, you should calculate next.
your answer is wrong when input is:
the correct output are all no solution.
For example, 25.
(251)/3=8
so after first person, still 16 coconuts left.
(161)/3=5
so after second person, still 10 coconuts left.
and after third person, 6 coconuts left. > result
AND,
6 can be divide by 3, so 3 people is right.
if the result can not divide by 3, you should calculate next.
your answer is wrong when input is:
Code: Select all
253
509
65539
16777209

 Learning poster
 Posts: 56
 Joined: Tue Jun 13, 2006 5:18 pm
 Location: (CSE, SUST) Sylhet, Bangladesh
 Contact:
616
I am getting WA with this, but I didn't found any wrong. Plese help some body. Here is my code.
Code: Select all
Removed after AC
Last edited by Mushfiqur Rahman on Sat Mar 03, 2007 3:16 pm, edited 1 time in total.