您的位置:首页 > 理论基础 > 计算机网络

hdu 2014西安赛区网络赛 5011Game

2014-09-14 19:36 429 查看
一做网络赛就感到压力十足 挤进前90 压力山大啊。。。

Game

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 72 Accepted Submission(s): 56



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

1
1
2
1 1
3
1 2 3




Sample Output

Win
Lose
Lose




说是跟SG函数有关的东西 将所有的数取异或值就可以了 判断是否大于0 大于0就是Win

至于说为什么 我也不造。。
http://baike.baidu.com/view/2855458.htm?fr=aladdin SG函数

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>

#define eps 1e-8
#define op operator
#define MOD  10009
#define MAXN  100100

#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define FOV(i,a,b)  for(int i=a;i>=b;i--)
#define REP(i,a,b)  for(int i=a;i<b;i++)
#define REV(i,a,b)  for(int i=a-1;i>=b;i--)
#define MEM(a,x)    memset(a,x,sizeof a)
#define ll __int64

using namespace std;

//int a[100010];
//priority_queue<int,vector<int>,less<int> > Q;

int main()
{
//freopen("ceshi.txt","r",stdin);
    int n;
    while(scanf("%d",&n)!=EOF)
    {
       int res=0;
       for(int i=0;i<n;i++)
       {
           int x;
           scanf("%d",&x);
           res=res^x;
       }
       if(res>0)  puts("Win");
       else puts("Lose");
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: