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 ...
随机推荐
- FreeMaker实现变量求和
今天在项目上遇到统计分页页面的某个字段的总和,前台页面是使用FreeMaker实现的,记录一下: <#assign tprice = 0 > <#list orderlist ...
- SUID, SGID, SBIT
基本上SUID有这样的限制与功能: SUID权限仅对二进位程序(binaryprogram)有效,不能用在shellscript上面: 运行者对於该程序需要具有x的可运行权限: 本权限仅在运行该程序的 ...
- 摘录ECMAScript官方文档中重要的两段话
Every object created by a constructor has an implicit reference (called the object’s prototype) to t ...
- Native wifi API使用
写于博客园,自己迁过来: 一.WlanOpenHandle打开一个客户端句柄 DWORD WINAPI WlanOpenHandle( __in DWORD dwClientVersion, __re ...
- find命令:忽略一个目录或者多个目录
example: find ./ ! -path "./output/*" ! -path "./output1/*" -type f | xargs grep ...
- Tcc学习笔记(一) 开篇
TCC,全称Tiny C Compiler(http://bellard.org/tcc/),是一个颇具特色的C编译器,你能把它当作一个C语言解释器来用,也可以嵌入你自己的应用程序作一个动态代码生成器 ...
- xshell xftp
xshell : http://www.netsarang.com/xshell_download.html xftp:http://www.netsarang.com/products/xfp_ov ...
- LeetCode OJ 116. Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
- [问题]数据库MySQL和Navicat的乱码问题
计算机中存储字符需要使用编码集,早期有ASCII集,但是随着技术的发展,ASCII集不能满足需求,出现了越来越多的字符,比如中文字符等.后来又发展出了Unicode.GB2312.utf8等字符集.字 ...
- Nginx-->基础-->安装-->001:安装总结
root@ubuntu:/data/src/nginx# ./configure --help --help print this message --prefix=PATH set installa ...