Noj 1083 Peanuts (ii)

Source: Internet
Author: User

Time limit: 1000ms memory limit: 10000K Total time: 3000ms

Describe:

51 Holiday The next day, Tom and Jerry found a pile of peanuts at the warehouse for a walk (the warehouse was strange). This time Tom worked out the following rules for peanuts:
1, Tom and Jerry take turns from the heap to remove K-grain peanuts eaten, K can be any number in the 1,5,10;
2, in order to show the fairness of the rules, Jerry can choose to take or post-fetch.
Jerry, of course, hopes that the last peanuts will be eaten by Tom. Please calculate whether Jerry should take first or later to achieve the goal.

Input:

There are several test examples, each sample input is an integer n,n greater than 0 is less than or equal to 1000, the number of peanuts.
N equals 0 means the input ends and no processing is required.

Output:

Each test example outputs an integer in a single line: Jerry first takes the output 1;tom first takes the output 0.

Input Sample:

1
2
3
4
0

Sample output:

0
1
0
1



#include <stdio.h>
intlist[1001]={0};//The judgement of taking the first peanut (list[0])
voidSearch ()
{
for(intI=1; i<=Ten; i++)//The rule of each artificial judgment when 1~10 grain
{//It can be seen that, if list[i]=1, there must be list[i-1]=0,list[i-5]=0.
if(i%2==0) list[i]=1;
Elselist[i]=0;
}
for(i= One; i<= +; i++)
{
if(list[i-1]==1&&list[i-5]==1&list[i-Ten]==1)
list[i]=0;//if after taking 1,5,10 grain should be taken by Jerry first to win, then let Tom First take, no matter how Tom takes, Jerry will win
Else
list[i]=1;//If Tom takes Jerry first and loses, then Jerry will win first (why?) ), now let Jerry take first
}
}
intMain ()
{
intN
Search ();
scanf"%d", &n);//Enter the first Test example
while(n)
{
printf"%d\n", List[n]);
scanf"%d", &n);
}
return0;
}View Code

Noj 1083 Peanuts (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.