hdu 5011

E - Game

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 5011

Appoint description: 
System Crawler  (2014-12-13)

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 < 10 5) means there are n piles of beads. The next line contains n postive integer, the i-th postive integer a i(a i < 2 31) means there are a i 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

NIM 博弈

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int n;
int main()
{
      while(scanf("%d",&n)!=EOF)
      {
            int t,sum;
            sum=0;
            while(n--)
            {
                scanf("%d",&t);
                sum=sum^t;
            }
            if(sum) printf("Win\n");
            else printf("Lose\n");
      }
      return 0;
}

  

时间: 2024-10-10 10:36:56

hdu 5011的相关文章

HDU 5011 Game(博弈论)

题目地址:HDU 5011 比赛的时候看那么多人过直接傻眼了..无奈,这题是真不会做,博弈论一点不会,得好好补补了.没想到这题的代码竟然是这样..当时想了好多水的方法乱蒙也没水过去.. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #includ

HDU 5011 Game(西安网络赛E题)

HDU 5011 Game 题目链接 思路:其实就求一个Nim和即可,要推也不难推,和为0下一个必然是胜态,因为至少取走一个,在怎么分也达不到原来那个值了,如果是非0值,就和原来Nim一样必然可以取一堆使得变成0 代码: #include <cstdio> #include <cstring> const int N = 100005; int n; long long a, sum; int main() { while (~scanf("%d", &

HDU 5011 Game(Nim博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5011 贴一发博弈的链接的链接:http://blog.csdn.net/u012860063/article/details/21816635 Problem Description Here is a game for two players. The rule of the game is described below: ● In the beginning of the game, ther

HDU - 5011 Game

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

hdu 5011 (nim博弈模版)

//nim博弈 //有n堆石头,两人轮流每次从一堆中拿至少1,之多全部的石头,没有石头可拿为lose //判断先手是win还是lose # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int main() { int n,i; __int64 a,sum; while(~scanf("%d",&n)) { sum=0; fo

Spring-1-E Game(HDU 5011)解题报告及测试数据

Game Time Limit:1000MS     Memory Limit:65536KB 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 ch

HDU 5011 Game Nim博弈 (涉及scanf和cin效率比较)

scanf是格式化输入,printf是格式化输出. cin是输入流,cout是输出流.效率稍低,但书写简便. 格式化输出效率比较高,但是写代码麻烦. 流输出操作效率稍低,但书写简便. cout之所以效率低,正如一楼所说,是先把要输出的东西存入缓冲区,再输出,导致效率降低. 缓冲区比较抽象,举个例子吧: 曾经就遇到过这样的情况(类似的), int i; cout<<'a'; cin>>i; cout<<'b'; 运行结果什么都没看到输出,输入一个整型比如3再按回车后ab同

hdu 1500 Chopsticks

http://acm.hdu.edu.cn/showproblem.php?pid=1500 dp[i][j]为第i个人第j个筷子. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int dp[1011][5011]; 7 int a[5011]; 8 int k,n; 9 int sqr(int x) 10 { 11 return x

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;