Hdu-1850-being a good boy in Spring Festival "Nim Game"

Source: Internet
Author: User

Being a good boy in Spring Festival

problem Description
A 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?" ”

Input
The input data contains multiple test cases, each of which occupies 2 rows, and the first line contains an integer m (1 < M <= 100) that 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.

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

Sample Input
3
5 7 9
0

Title Link: HDU 1850

The question: Nim problem, there are a number of n heap of items, two people take turns from a heap of any number of items, the provision of at least one at a time, more than open, the last to win the light. Ask, if the initiator wants to win, the first step has several choices?

Topic idea: Optional number is arbitrary. That is, SG (x) = x; Ans = The result of an XOR of the SG value of all heaps

If you want to win, the first step has several options?

Here's the code:

#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>#include <string>#include <set>#include <functional>#include <numeric>#include <stack>#include <map>#include <queue>#include <iomanip>using namespace STD;intMain () {intM while(Cin>> m && m) {inta[ the],sum =0; for(inti =0; I < m; i++) {Cin>> A[i];        Sum ^= a[i]; }cout<< sum << Endl;intCNT =0; for(inti =0; I < m; i++) {if(A[i] > (sum ^ a[i])) cnt++; }cout<< CNT << Endl; }return 0;}

Hdu-1850-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.