Being a good boy in Spring Festival (Nim game variant)

Source: Internet
Author: User
Being a good boy in Spring Festival Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5069 Accepted Submission (s): 3034


Problem Description a year outside parents time
Spring Festival Home Can you do a few days good boy?
Try to do the following things in winter vacation

Spend time with mom on the vegetable
Quietly buy a little gift for dad
Take the initiative to ask for a bowl wash once and for all
One day get up early and give mom and dad a heart for breakfast.

You can talk to Mom and dad if you want.
Let's play a little game. ACM Class to School ~

Here is a two-person mini-game: There are m stacks of poker on the table, and the number of cards per pile is ni (i=1 ... M); The two take turns, and each step can be arbitrarily selected and taken away from any of the cards; the poker on the table is all out, then the game is over; the last person to pick the card is the winner.
Now we do not want to study whether to win or negative, I just want to ask you:
-"If the initiator wants to win, there are several choices in the first step." ”

The input data contains multiple test cases, each with 2 rows, and the first line contains an integer m (1<m<=100), which represents the number of stacks of poker, followed by a line containing M-integers Ni (1<=ni<=1000000,i=1 ... m), representing the number of M-Heap poker, respectively. An M of 0 indicates the end of the input data.

Output if the initiator can win, please export his first feasible number of scenarios, otherwise please output 0, the output of each instance takes up one row.

Sample Input
3 5 7) 9 0
Sample Output
1
Author LCY
Source ACM Short Term EXAM_2007/12/13



#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
# Include <queue>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=110;
int A[MAXN];
int main ()
{
    int n;
    while (Cin>>n)
    {
        if (n==0) break;
        int i,ans=0,num=0;
        for (i=0;i<n;i++)
        {
            cin>>a[i];
            Ans^=a[i];
        }
        if (ans==0) cout<<0<<endl;
        else
        {for
            (i=0;i<n;i++)
                if ((A[i]^ans) <a[i]) num++;
            cout<<num<<endl;
}
}} /* The extraction of the
    no-stack cards in the topic can be considered a standalone game, so the SG value of the independent game can be obtained by the SG theorem.
    first write the code to play the SG function value table. Find the law, sg[i]=i;
    The ans=a[0]^a[1]^ is obtained by the SG theorem. ^a[n-1], called Nim and, also called XOR and
    when Ans=0, the initiator will be defeated.
    when Ans!=0, want to win, then the first step must be to make the remaining number of Nim and 0. Must be a pile of cards to reduce the change so that Nim and 0, and the
other T=a[i]^ans, then T and the rest of the a[j] Nim and must be 0, so long as t<a[i], you can draw this set of cards to the initiator
* *


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.