Peanuts (four)

Source: Internet
Author: User
Tags time limit

Original blog: Peanuts 4

1085. Peanuts (four)
Time limit: 1000ms memory limit: 10000K Total time limit: 3000ms
Describe
51 Long holiday on the fourth day, Tom visited N BBs, did n^2 a brain problem, finally found that every time after eating peanuts mouth is the reason for bitterness: I will always eat the last grain of peanuts.
On the fifth day of the 51 holiday, Tom and Jerry found n heaps of peanuts when they were walking in the warehouse. )。 This time Tom made the following rules for peanuts:
1, the first selection of the most bitter peanuts, put in a bottle;
2, Tom and Jerry take turns from any pile of peanuts to remove any grain to eat;
3. If Tom eats the last grain of peanuts (except peanuts in the bottle), Jerry must eat the peanuts in the bottle, and if Jerry eats the last peanuts (except peanuts in the bottle), Tom voluntarily eats the peanuts in the bottle.
4, 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 several examples.
The first line of the input for each sample is an integer n,n greater than 0 is less than or equal to 10, representing the heap number of peanuts (after the most bitter peanuts); the next n row is a positive integer of not more than 100 in each row, representing a pile of peanuts (after taking the most bitter peanuts).
N equals 0 means that the input ends and no processing is required.

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

Input sample
2
1
1
2
1
100
0

Output sample
0
1
This is a typical game algorithm, converted into 01, to maintain the balance of state.

#include <stdio.h> int a[10]; int b[10][7];
2^7=128>100,7 bit small enough for int n;
int change ();
void com (int m);
    int main () {int i,j,k;
    scanf ("%d", &n);
        while (n!=0) {for (i=0;i<n;i++) scanf ("%d", &a[i]);
        for (i=0;i<n;i++) for (j=0;j<7;j++) b[i][j]=0;
        K=change ();
        printf ("%d\n", K);
    scanf ("%d", &n);
return 0;
    int change () {int i,j,flag;
    for (i=0;i<n;i++) COM (i);
        for (i=0;i<7;i++) {flag=0; A for (j=0;j<n;j++) {if (b[j][i]==1) Flag=1-flag;////////////////////////////////////////////////////////// 
			Greater than 0),//This is the last to win, by the Match Game know: S state, as long as the correct method, will win. http://www.cnblogs.com/tanky_woo/archive/2010/08/20/1804464.html} if (flag==1) break;
    Once the flag=1 is found, it exits the loop and returns 1} if (flag==1) return 1;
else return 0;
    } void com (int m) {int t=a[m],p;
    int i;
        for (i=0;i<7;i++) {P=T/2; b[m][i]=t-p*2;
    Converting A[m] into a 7-bit binary representation of a number of T=T/2; }
}


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.