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 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

题解:

  1. 这道题是典型的Nim游戏,与Nim游戏不同的是该题中除了至少拿走一颗珠子以外,还可以将该堆剩下的珠子分为两堆,其实这对游戏的胜负判断是没有影响的。因为至少拿走了一颗珠子,那么xor求和,之前为0,拿走珠子以后,无论是否将剩下的该堆珠子分为两堆,此时的xor和必不为零,反之亦然。

  2. 关于Nim游戏,已经有大量的解释,在此略过。

​以下是代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <sstream>
#include <queue>
using namespace std; #define F(i,s,e) for(int i = s;i<e;i++)
#define ss(x) scanf("%d",&x)
#define write() freopen("1.in","r",stdin)
#define W(x) while(x) int main(){
//write();
int n,t,sum;
W(ss(n)!=EOF){
sum=0;
W(n--){
ss(t);
sum^=t;//对所有的输入xor求和
}
if(sum)printf("Win\n");
else printf("Lose\n");//和为零,则先手必输
}
}

  

Spring-1-E Game(HDU 5011)解题报告及测试数据的更多相关文章

  1. BestCoder18 1002.Math Problem(hdu 5105) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...

  2. BestCoder17 1002.Select(hdu 5101) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...

  3. BestCoder8 1001.Summary(hdu 4989) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989 题目意思:给出 n 个数,然后将这些数两两相加,得到 n*(n-1) /2 对和,把重复的和去掉 ...

  4. BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150 题目意思:就是直接求素数. 不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊---- ...

  5. BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...

  6. BestCoder20 1002.lines (hdu 5124) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...

  7. BestCoder19 1001.Alexandra and Prime Numbers(hdu 5108) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5108 题目意思:给出一个数正整数 N,N <= 1e9,现在需要找出一个最少的正整数 M,使得 ...

  8. BestCoder17 1001.Chessboard(hdu 5100) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5100 题目意思:有一个 n * n 的棋盘,需要用 k * 1 的瓷砖去覆盖,问最大覆盖面积是多少. ...

  9. BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...

随机推荐

  1. boost实用工具:创建一个禁止复制的类 noncopyable

    boost的noncopyable允许创建一个禁止复制的类,使用很简单,但很好用!  C++ Code  12345678910111213141516171819202122232425262728 ...

  2. hdu 2686(状压dp)

    题目链接:http://poj.org/problem?id=2686 思路:典型的状压dp题,dp[s][v]表示到达剩下的车票集合为S并且现在在城市v的状态所需要的最小的花费. #include& ...

  3. XAML 中使用空格键(空白字符)

    默认情况下,XAML折叠所有空白,这意味着包含空格.tab 键以及回车的长字符串将被转换为单个空格.而且,如果在一个元素内容之前或之后添加空白,这个空格将被完全忽略. 有时这并不是所期望的结果.例如, ...

  4. 九度OJ 上剑指 offer 习题目录

    <剑指Offer>面试题集收录汇总 面试题1 赋值运算符函数 不适合在线模式 面试题2 实现Singleton模式 不适合在线模式 面试题3 二维数组中的查找 已收录 面试题4 替换空格 ...

  5. malloc free, new delete 的异同点

    相同点: 都可以动态的申请并释放内存 不同点: 1. 用法不同 <1> malloc 函数为 void* malloc(size_t size), 用于申请一块长度为 size 字节的内存 ...

  6. iOS开发之 -- CocoPods的安装和使用

    以前项目中使用过Pods 1.0,最近项目中也有用到,因为很长时间没用了,所以配置了下,谁知道,中间出现了不少坑,特记录在此博客,其实pods的使用也就是几个终端命令而已,可能随着系统的升级,以前的终 ...

  7. 第十六篇:Linux系统编程中环境变量的使用

    前言 在 UNIX Like 系统中,存有各类系统/应用程序的环境变量,可通过修改之改变系统/应用程序的执行效果:除此之外,用户还可以定义自己的环境变量,供自己写的程序使用. 本文将说明如何在程序中设 ...

  8. 【BZOJ4551】[Tjoi2016&Heoi2016]树 并查集

    [BZOJ4551][Tjoi2016&Heoi2016]树 Description 在2016年,佳媛姐姐刚刚学习了树,非常开心.现在他想解决这样一个问题:给定一颗有根树(根为1),有以下两 ...

  9. LeetCode 笔记系列16.1 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]

    题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...

  10. 170421、maven自定义变量及属性

    一.自定义变量 <!-- 全局属性配置 --> <properties> <project.build.name>tools</project.build.n ...