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

Problem Description
Two
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.
 
Input
Intput contains multiple test cases. The first line is an integer 1≤T≤100,
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)
 
Output
For each test case,output a line whick contains either"First player wins."or"Second player wins".
 
Sample Input
2
2
4 4
3
1 2 4
 
Sample Output
Second player wins.
First player wins.
 
Author
UESTC
 
Source
 最近学长讲博弈论  给我们讲了些题目 包括这道题 
主要是求sg函数,打表1-40就可以看出规律,(带码学别人的)
x%8==7 sg()=x+1;
x%8==0 sg()=x-1;
其他  sg()=x
 #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的更多相关文章

  1. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  3. HDU 5795:A Simple Nim(博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description   Two players take t ...

  4. HDU 5795 博弈

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Time Limit: 2000/1000 MS (Java/Oth ...

  5. HDU 5795 A Simple Nim (博弈 打表找规律)

    A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...

  6. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  7. HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. HDU 5795 A Simple Nim

    打表找SG函数规律. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...

  9. hdu 5795 A Simple Nim 博弈sg函数

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Pro ...

随机推荐

  1. [delphi]运行cmd命令,并取得输出字符

     http://blog.csdn.net/nerdy/article/details/8969189 [delphi]运行cmd命令,并取得输出字符 标签: delphiCMD命令 2013-05- ...

  2. Ajax基本结构

    $.ajax({ url: "连接到的一般处理程序", data: { "服务端获取时的名称": 获取的用户端的值 }, type: "post&qu ...

  3. mysql 常用查询

    1.unix时间戳的使用 unix_timesamp.from_unixtime 函数 和 datatime_format函数. // 从datetime 类型取做整形 unixtime时间戳; se ...

  4. eclipse导出jar包的方法

    第一:导出基本项目的jar包(此项目没有引用过第三方jar包) 1.在eclipse中选择你要导出的项目或package或类,右击,选择Export子选项: 2.在弹出的对话框中,选择java文件-- ...

  5. python积累

    python积累 一.逐渐积累 python逐渐积累 http://www.cnblogs.com/lx63blog/articles/6051526.html python积累_2 http://w ...

  6. JQuery easyui 笔记

    1.控件启用,禁用 $form.find("input[type!='button']").removeAttr("readonly"); $form.find ...

  7. exit

    -------siwuxie095 三个退出命令: exit exit /b goto :eof 这三个命令都可以退出批处理,但之间有细微差别: (1)运行 GOTO :EOF 后,CMD返回并将等待 ...

  8. ASP.NET应用中会话状态丢失及解决策略

    会话易丢失,解决办法 一. 了解下Web园 一个应用程序池默认是开启一个工作进程,但也可以开启多个工作进程,这样可提高性能,这个功能名为Web园,是小型的“Web农场”,您无需使用多台计算机来传送相同 ...

  9. eclipse项目自动发布到tomcat目录,缺文件。

    eclipse项目自动发布到tomcat目录,缺文件. 解决方案: 项目--Properties-->Deployment Assembly-->Add--> Folder Add- ...

  10. Linux用户和组的管理操作

    用户和组的管理操作 命令中涉及的单词和简写: 用户:user:组:group : 增加:add :  修改:modify  mod ;  删除 : delete  del 增加用户     /etc/ ...