hdu1850 Being a good boy in Spring Festival (NIM game)

Source: Internet
Author: User
Tags gcd

Being a good boy in Spring Festival

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 6682 Accepted Submission (s): 4039


problem Descriptiona year away from parents are worried about
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, the first step has several options?" ”

InputThe input data contains multiple test cases, each of which occupies 2 rows, and the first line contains an integer m (1<m<=100), which represents the number of stacks of poker, followed by a row 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.

Outputif the initiator can win, please output his first feasible number of scenarios, otherwise please output 0, each instance output one row.

Sample Input
35 7 90

Sample Output
1

AuthorLCY
SourceACM Short term EXAM_2007/12/13


Test instructions: Chinese question ..... It doesn't explain ....

Analysis: A basic NIM game problem, know a^b=c,a^c=b,b^c=a; the problem is solved.

#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue > #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm>  Using namespace Std;const double eps = 1e-6;const double pi = ACOs ( -1.0); const int INF = 1e9;const int MOD = 1e9+7; #define ll long Long#define CL (b) memset (A,b,sizeof (a)) #define Lson (i<<1) #define Rson ((i<<1) | |) #define N 50010in T gcd (int a,int b) {return B?GCD (b,a%b): A;}        int N,a[110];int Main () {while (scanf ("%d", &n), n) {int sum=0,ans=0;            for (int i=0; i<n; i++) {scanf ("%d", &a[i]);        Sum ^= a[i];        } if (sum==0) {cout<<0<<endl; continue;}        for (int i=0; i<n; i++) {if ((Sum^a[i]) <= a[i]) ans++;    } cout<<ans<<endl; } return 0;}


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

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.