打表找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. 向多个会话窗口发送命令 -SecureCRT

    1.前提 一个服务可能部署在多台机器上,这时如果要查问题,最繁复的方法就是打开该服务的每个session,把命令在每一台机器上复制一下执行,找到相关的日志:还有一种方法就是一条命令同时向多个会话窗口发 ...

  2. html 页面太长滚动时,固定页面菜单标签,或者导航标签的位置,fixed/stickUp the position

    有时你曾经需要把页面上的某些东西当页面太长发滚动的时候保留置顶位置显示,或许你有别的实现方式,我这个仅供参考, 源代码: /*global $, jQuery, alert*/ (function ( ...

  3. 扔鸡蛋问题详解(Egg Dropping Puzzle)

    http://blog.csdn.net/joylnwang/article/details/6769160 经典的动态规划问题,题设是这样的:如果你有2颗鸡蛋,和一栋36层高的楼,现在你想知道在哪一 ...

  4. Jenkins2.32.1+svn+maven安装配置与构建部署

    这两天学习了一下持久化集成工具Jenkins,在自己的本地搭建一个简单的Jenkins环境. 使用环境:Windows64系统,JDK1.8,eclipse,svn(Windows版本VisualSV ...

  5. python 基础学习-总结1

    1.Python 简介 易学易懂,语法简单 不需编译,即可运行 比其他语言更简洁 不需要管理内存 1.1 什么是Python? python 是由Guido.van.Rossum于1989年始创,其根 ...

  6. cxf 报错:java.lang.NoSuchMethodError: org.apache.ws.commons.schema.XmlSchemaCollection.read(Lorg/w3c/dom/Document;Ljava/lang/String;)

    由于没有仔细查看官方提供的文档,由jdk版本不一致导致的出错: http://cxf.apache.org/cxf-316-release-notes.html 自己使用的是jdk1.8. 报Exce ...

  7. JavaScript创建读取cookie代码示例【附:跨域cookie解决办法】

    使用JavaScript 原生存取cookie代码示例: var cookie = { set : function(name, value, expires, path, domain, secur ...

  8. 在Eclipse中安装testNG插件

    1. 选择菜单:Help->Install New Software,点击Add按钮输入框中输入相应的Name:testNG和Location:http://beust.com/eclipse. ...

  9. droidcon 北京2016安卓技术大会——安卓领域国际盛会

    目前droidcon国际技术大会已成为安卓领域全球最有影响力.规模最大的技术大会,每年在世界各地举办,横跨四大洲,超过上万人次参加. droidcon国际技术大会于2009年由一个Android爱好者 ...

  10. C socket指南

    1.介绍 Socket 编程让你沮丧吗?从man pages中很难得到有用的信息吗?你想跟上时代去编Internet相关的程序,但是为你在调用 connect() 前的bind() 的结构而不知所措? ...