Original Blog: Peanuts 5
Peanuts (v)
Time limit: 1000ms memory limit: 10000K Total time limit: 3000ms
Describe:
On the sixth day of the 51 holiday, Tom met Kitty on QQ. Oh, Kitty, in the discrete math class to know the PPMM ... Wait a minute. Tom suddenly understood: his life in addition to see the post not back the biggest mistake is discrete mathematics did not learn.
On the seventh day of the 51 holiday, Tom and Jerry found a pile of peanuts during a walk in the warehouse (warehouse, hehe, warehouse ...). )。 This time Tom made the following rules for peanuts:
1, the first selection of the most bitter peanuts, put in a bottle;
2, the remaining peanuts made peanut butter, Tom and Jerry took turns to take some peanut butter to eat;
3, the first person to take only 1.0 grams, after the number of peanut butter can not be less than two people have taken the total number and not more than two people have taken the total number of three times times;
4, can not follow the rule 3 to get peanut butter people must eat the bottle of peanuts;
5, to show the fairness of the rules, Jerry can choose to take first or later.
Jerry certainly wanted the peanuts in the bottle to be eaten by Tom. Please calculate whether Jerry should take it first or later in order to achieve the goal.
Input:
There are a number of examples, each example of the input is a floating-point number w,w greater than 1.0 is less than or equal to 1000.0,w at most only a decimal, representing the amount of peanut butter, the unit for grams.
W is less than 0 for the end of input and does not need to be processed.
Output:
Each example outputs an integer in a single line: Jerry first takes the output 1;tom 0.
Input Sample:
1.5
7.9
-1
Output Sample:
1
0
This is also a problem of dynamic planning.
#include <stdio.h>
int a[10001];
float m;
int n;
int search ();
int main () {
int an;
scanf ("%f", &m);
n=m*10;
while (n>=0) {
an=search ();
if (an) printf ("0\n");
else printf ("1\n");
scanf ("%f", &m);
N=m*10
}
}
int search () {
int i,j,k,flag;
for (i=0;i<10001;i++) a[i]=0;
for (i=n;i>9;i--) {//i said already ate I, the smallest take 1.0 grams, and magnified 10 times times, so more than 9
flag=0;
j=n-i;//left J
if (i>j) a[i]=0;//at this time, has taken more than not to take, then the next time do not meet the conditions of 3, it will eat bitter peanuts, will lose, so let Tom take
else{
if (j <=3*i) a[i]=1;//At this point, the time can also be taken to meet the conditions of 3, so, can let Jerry take.
else{for
(k=i;k<=3*i;k++) {//The number of each fetch cannot be less than the total quantity that two people have taken, so start with I
if (a[i+k]==0) {flag=1;break;} In the future there is a situation where Jerry will win when Tom takes it, so Jerry can take the right amount of peanuts to get to that point.
}
if (flag==1) a[i]=1;
else a[i]=0;
}
}
return a[10];
}