hdu 5795
A Simple Nim
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 948 Accepted Submission(s): 559
players take turns picking candies from n heaps,the player who picks
the last one will win the game.On each turn they can pick any number of
candies which come from the same heap(picking no candy is not
allowed).To make the game more interesting,players can separate one heap
into three smaller heaps(no empty heaps)instead of the picking
operation.Please find out which player will win the game if each of them
never make mistakes.
the number of test cases. Each case begins with an integer n,
indicating the number of the heaps, the next line contains N integers s[0],s[1],....,s[n−1], representing heaps with s[0],s[1],...,s[n−1] objects respectively.(1≤n≤106,1≤s[i]≤109)
2
4 4
3
1 2 4
First player wins.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int visited[];
int sg[];
int main(){
/*int i,j,k;
for(i=1;i<40;i++){
memset(visited,0,sizeof(visited));
for(j=0;j<i;j++)visited[sg[j]]=1;
for(j=1;j<i;j++){
for(k=1;k+j<i;k++){
visited[sg[j]^sg[k]^sg[i-k-j]]=1;
}
}
for(j=0;j<40;j++){
if(visited[j]==0){
break;
}
}
sg[i]=j;
}
for(i=1;i<40;i++){
cout<<i<<" "<<sg[i]<<endl;
}*/
int t;
scanf("%d",&t);
int n,i,x;
int ans;
while(t--){
scanf("%d",&n);
ans=;
for(i=;i<n;i++){
scanf("%d",&x);
if(x%==){
x=x-;
ans=ans^x;
}
else if(x%==){
x=x+;
ans=ans^x;
}
else
ans=ans^x; }
cout<<ans<<endl;
}
}
hdu 5795的更多相关文章
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- HDU 5795:A Simple Nim(博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description Two players take t ...
- HDU 5795 博弈
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 5795 A Simple Nim
打表找SG函数规律. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...
- hdu 5795 A Simple Nim 博弈sg函数
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
随机推荐
- mysql优化要点(一)
一 sql语句中使用函数需要注意,因为有可能结果每条语句都会调用,甚至表内每条记录都会调用. 二 注意转换,会消耗大量性能,甚至字符串的encoding不同,也会出现非常大的消耗 三 myisa ...
- Acadia Lab 203 + Lab 231
在做完 Lab 6 之后,惊觉选做实验缺口很大,于是遍历了一遍夏任务,找到了一条最省力的路线. 做完 Lab 6 的连线不用拆,可以接下来做以下两个实验: Lab 203 网络时钟 核心代码如下: v ...
- Linux驱动学习之什么是驱动?
一.什么是驱动? 1: 驱动一词的字面意思 2: 物理上的驱动 3: 硬件中的驱动 4: linux内核驱动.软件层面上的驱动广义上是指:这一段代码操作了硬件去动,所以这一段代码就叫硬件的驱动程序. ...
- cenos 7常用操作
centos 虚拟机 <一>设置ip <1>虚拟机配置ip 虚拟机->设置->网络适配器->设置NAT模式 <2>编辑->虚拟网络编辑器,对 ...
- Java中public,private,protected,和默认的区别
Java中public,private,protected,和默认的区别 1.private修饰词,表示成员是私有的,只有自身可以访问: 2.protected,表示受保护权限,体现在继承,即子类可以 ...
- PHP入门篇
一.PHP-什么是变量 变量是用于存储值的,我们命令服务器去干活的时候,往往需要产生一些数据,需要临时性存放起来,方便取用.我们也可以理解为,变量就像一个购物袋,我们可以用来装苹果.榴莲(当然也可以 ...
- python random
import randoma = random.randrange(0,5)print(a)本来很正常的一段代码,用pycharm就报错,控制台就可以运行,原来random 和自带的random 同名 ...
- POJ2186
poj2186 popular cows Every cow's dream is to become the most popular cow in the herd. In a herd of ...
- .NET MVC TempData、ViewData、ViewBag
说明: 原文作者贤新 原文地址:http://www.cnblogs.com/chenxinblogs/p/4852813.html ViewData和ViewBag主要用于将数据从控制器中传递到视图 ...
- 说说我的企业级应用上线历程(A little different!)
刚到公司时,我还是一个个人应用都没上线过的小白一枚,甚至都不知道.p12文件,不知道个人应用上线所使用的证书只能是自己机子创建的发布证书才可以打包上线,不知道企业级应用如何打包,不巧的是我还赶上了 i ...