Revenge of Nim

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 562    Accepted Submission(s): 290

Problem Description
Nim
is a mathematical game of strategy in which two players take turns
removing objects from distinct heaps. On each turn, a player must remove
at least one object, and may remove any number of objects provided they
all come from the same heap.
---Wikipedia

Today, Nim takes
revenge on you. The rule of the game has changed a little: the player
must remove the objects from the current head(first) heap. Only the
current head heap is empty can the player start to remove from the new
head heap. As usual, the player who takes the last object wins.

 
Input
The first line contains a single integer T, indicating the number of test cases.

Each
test case begins with an integer N, indicating the number of heaps.
Then N integer Ai follows, indicating the number of each heap
successively, and the player must take objects in this order, from the
first to the last.

[Technical Specification]
1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. 1 <= Ai <= 1 000 000 000

 
Output
For each test case, output “Yes” if the first player can always win, otherwise “No”.
 
Sample Input
2
1
2
2
1 1
 
Sample Output
Yes
No
 
Source
 
题意:按照顺序取完n堆石子,每次取一个或者一堆。
关键点:看出取到第一个>1的石子堆的人是必胜态。
/**
对于某个人来说,只要他能够取到第一个>1的堆,那么他就可以决定后面的人的状态了,所以第一个取到>1的堆的人
是赢家。所以我们只要讨论前面有多少==1的堆就行了。
2.如果里面存在>1的堆,那么在第一个>1的堆前面有偶数个=1的堆先手才会赢
1.如果没有>1的堆,那么奇数个=1的堆先手就会赢。
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL; int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n,cnt=,v;
bool flag = false;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&v);
if(v>&&!flag)
{
flag = true;
cnt = i-;
}
}
if(!flag) cnt = n;
if(flag){
if(cnt%==) printf("No\n");
else printf("Yes\n");
}else{
if(cnt%==) printf("No\n");
else printf("Yes\n");
}
}
return ;
}

最新文章

  1. Permit.js – 用于构建多状态原型的 jQuery 插件
  2. Android内容观察者
  3. wget的使用详解
  4. 聊聊HTTPS和SSL_TLS协议
  5. C++不完整的类型
  6. Codeforces Round #247 (Div. 2) C题
  7. hdu 5264 pog loves szh I 水题
  8. SQLserver中的xp_cmdshell
  9. Could not parse mapping document from resource cn/spt/model/Student.hbm.xml
  10. android滑动删除的多种实现方式(一)
  11. The Time in Words
  12. 你真的会玩SQL吗?透视转换
  13. 斐波那契数列第n项的值及前n项之和
  14. sed 命令简介
  15. HDU6011
  16. phpstorm 找到文件修改历史
  17. Struts vs spring mvc
  18. 定时任务 Wpf.Quartz.Demo.5 (升级版)
  19. Python 3 进阶 —— print 打印和输出
  20. [Selenium.2.Testing.Tools.Beginners.Guide]读书笔记

热门文章

  1. Kali 安装VMtools(最新)
  2. SJTU 1077 加分二叉树
  3. 6 json和ajax传递api数据
  4. Git的安装及常用操作
  5. java以正确的方式停止线程
  6. loj6387 「THUPC2018」绿绿与串串 / String
  7. cf975d Ghosts
  8. 51、如何提取android代码中的字符串为系统资源文件 (I18N)
  9. ogre3D学习基础19 --- 材质的继承,纹理的滚动与旋转
  10. PostgreSQL 如何优化索引效率