hdu 5011 Game Nim博弈 2014 ACM/ICPC Asia Regional Xi'an Online

来源:互联网 发布:mysql 数据库文件类型 编辑:程序博客网 时间:2024/05/01 14:54

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5011

Problem Description
Here is a game for two players. The rule of the game is described below:

● In the beginning of the game, there are a lot of piles of beads.

● Players take turns to play. Each turn, player choose a pile i and remove some (at least one) beads from it. Then he could do nothing or split pile i into two piles with a beads and b beads.(a,b > 0 and a + b equals to the number of beads of pile i after removing)

● If after a player's turn, there is no beads left, the player is the winner.

Suppose that the two players are all very clever and they will use optimal game strategies. Your job is to tell whether the player who plays first can win the game.
 

Input
There are multiple test cases. Please process till EOF.

For each test case, the first line contains a postive integer n(n < 105) means there are n piles of beads. The next line contains n postive integer, the i-th postive integer ai(ai < 231) means there are ai beads in the i-th pile.
 

Output
For each test case, if the first player can win the game, ouput "Win" and if he can't, ouput "Lose"
 

Sample Input
1121 131 2 3
 

Sample Output
WinLoseLose
 

Source
2014 ACM/ICPC Asia Regional Xi'an Online
 

Nim博弈..

代码:

#include <algorithm>#include <cstdlib>#include <iostream>#include <cstring>#include <cstdio>#include <vector>#include <cctype>#include <cmath>#include <stack>#include <queue>#include <list>#include <map>#include <set>using namespace std;#define min2(x, y)     min(x, y)#define max2(x, y)     max(x, y)#define min3(x, y, z)  min(x, min(y, z))#define max3(x, y, z)  max3(x, max(y, z))#define clr(x, y)      memset(x, y, sizeof(x))#define fr(i,n)        for(int i = 0; i < n; i++)#define fr1(i,n)       for(int i = 1; i < n; i++)#define upfr(i,j,n)    for(int i = j; i <= n; i++)#define dowfr(i,j,n)   for(int i = n; i >= j; i--)#define scf(n)         scanf("%d", &n)#define ptf(n)         printf("%d",n)#define ptfs(s)        printf("%s",s)#define ptln()         printf("\n")#define srt(a,n)       sort(a,n)#define LL long long#define pi acos(-1.0)#define inf 1 << 31-1#define eps 0.00001#define maxn 100005int main(){        int n;        while(scf(n) != EOF)        {            int k;            __int64 ans = 0;            fr(i,n)            {                scf(k);                ans = ans ^ k;            }            if(!ans)                printf("Lose\n");            else                printf("Win\n");        }    return 0;}


0 0
原创粉丝点击