打表找SG函数规律。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} int sg[],f[]; int main()
{
sg[]=;
for(int i=;i<=;i++)
{
memset(f,,sizeof f); for(int j=;j<i;j++) f[sg[j]]=; for(int j=;j<=i;j++)
{
for(int k=;k<=i;k++)
{
for(int s=;s<=i;s++)
{
if(j+k+s!=i) continue;
f[sg[j]^sg[k]^sg[s]]=;
}
}
}
for(int j=;j<;j++) if(f[j]==) {sg[i]=j;break;}
}
for(int i=;i<=;i++) printf("i:%d sg[i]:%d\n",i,sg[i]);
return ;
}

然后就可以轻松AC了...

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int T,n; LL ans,x; LL SG(LL x)
{
if(x==)return ; if(x==) return ;
if(x%==) return x-; if((x+)%==) return x+;
return x;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); ans=;
for(int i=;i<=n;i++) scanf("%lld",&x), ans=ans^SG(x);
if(ans) printf("First player wins.\n");
else printf("Second player wins.\n");
}
return ;
}

HDU 5795 A Simple Nim的更多相关文章

  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 (博弈 打表找规律)

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

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

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

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

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

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

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

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

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

  7. HDU 5795 A Simple Nim ——(Nim博弈 + 打表)

    题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作. 分析:打表找sg值的规律即可. 感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~ 打 ...

  8. HDU 5794 - A Simple Nim

    题意:    n堆石子,先拿光就赢,操作分为两种:        1.任意一堆中拿走任意颗石子        2.将任意一堆分成三小堆 ( 每堆至少一颗 )        分析:    答案为每一堆的 ...

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

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

随机推荐

  1. sublime插件(配合nodejs环境)

    一.首先先安装nodejs,从nodejs官网下载 www.nodejs.cn 下载完成后直接安装,选择npm package版本的进行安装,安装完成后无需配置环境变量,nodejs会自动进行配置. ...

  2. Objective-C与Swift下的自定义打印函数(Debug和Release)

    1.Objective-C 在使用Objective-C进行开发的过程中,为了Debug会不断的设置打印函数.如下图是我们经常用的,用来测试监听方法的实现与否: NSLog(@"%s&quo ...

  3. 万恶的tileMap

    先吐槽下.. 本来,我们准备用tileMap来做地图的,但发现一个问题,就是tileMap层中不能添加cc.Sprite,这导致了tileMap只适合做2D平面没有遮挡的游戏,并且主角是不能有效率的进 ...

  4. 关于function

    场景:让用户输入一个数字,程序由1+2....一直累加到用户输入的数字为止 #!/bin/bashPATH=$PATH:~/scriptexport PATH #chech whether the i ...

  5. 如何在高并发的分布式系统中产生UUID

    一.数据库发号器 每一次都请求数据库,通过数据库的自增ID来获取全局唯一ID 对于小系统来说,这是一个简单有效的方案,不过也就不符合讨论情形中的高并发的场景. 首先,数据库自增ID需要锁表 而且,UU ...

  6. 去除右键的opendgl

    Windows Registry Editor Version 5.00[-HKEY_CLASSES_ROOT\Unknown\shell\opendlg][-HKEY_CLASSES_ROOT\Un ...

  7. 分布式版本控制系统Git-----6.Git 常见命令一览表

    说明/备注 命令 备注 保存更新 git add [-i] -i 逐个确认 检查更新 git status 提交更新 git commit [-a] -m "<更新说明>&quo ...

  8. 阻塞与非阻塞、同步与异步 I/O模型

    I/O模型 Linux 下的五种I/O模型 阻塞I/O(blocking I/O) 非阻塞I/O (nonblocking I/O) I/O复用(select 和poll) (I/O multiple ...

  9. linux版本选择

    桌面系统           -- Ubuntu,开发人员也喜欢用Ubuntu 服务器端           -- RHEL或CentOS,RHEL要钱 对安全要求很高  -- Decian或Free ...

  10. [妙味DOM]第三课:Event-事件详解1

    知识点总结 焦点事件 onfocus 获取焦点 onblur 失点焦点 obj.focus() 给指定元素设置焦点 obj.blur() 取消指定元素的焦点 obj.select() 选择指定元素里的 ...