HDU 5795 A Simple Nim
打表找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的更多相关文章
- 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 (博弈 打表找规律)
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打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu 5795 A Simple Nim 博弈sg函数
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- HDU 5795 A Simple Nim ——(Nim博弈 + 打表)
题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作. 分析:打表找sg值的规律即可. 感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~ 打 ...
- HDU 5794 - A Simple Nim
题意: n堆石子,先拿光就赢,操作分为两种: 1.任意一堆中拿走任意颗石子 2.将任意一堆分成三小堆 ( 每堆至少一颗 ) 分析: 答案为每一堆的 ...
- HDU 5795:A Simple Nim(博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description Two players take t ...
随机推荐
- C#第十一天(winform)
1.MD5 namespace MD5加密与解密 { class Program { static void Main(string[] args) { "); Console.WriteL ...
- TOMcat9 免安装版的配置
在这里默认大家都安装了jdk并且配置了java的环境,网上教程很多. 在tomcat官网(http://tomcat.apache.org/download-90.cgi)上下载和自己系统匹配的安装包 ...
- Hive 常用函数
参考地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1. parse_url(url, partToExt ...
- 如何让文字和input框水平放在div里
#text_input { height: 16px; width: 133px; margin-right: 5px; padding:0 0 0 3px; border: 1px solid #C ...
- Mybatis(一)
jdbc开发 1)优点:简单易学,上手快,非常灵活构建SQL,效率高 2)缺点:代码繁琐,难以写出高质量的代码(例如:资源的释放,SQL注入安全性等) 开发者既要写业务逻辑,又要写对象的创建和销毁, ...
- Redis链表相关操作命令
lists链表类型lists类型就是一个双向链表,通过push,pop操作.从链表的头部或者尾部添加删除元素,这样list即可以作为栈也可以作为队列 lpush key value 在链表key的头部 ...
- 字符串ID转换成字符串名字
select U.CnName+',' from f_splitstr('1828,1055333,1,1035681,752,494,22549,219,23860,478,23453,677, ...
- html 超链接(a)详细讲解
a:link : http://www.cnblogs.com/yangfeng/archive/2009/07/25/1530962.html 超级链接 超级链接是网站中使用比较频繁的HTML元素, ...
- 《JS权威指南学习总结--第十一章子集和扩展》
js子集和扩展:http://www.cnblogs.com/ahthw/p/4298449.html ES6新增let和const关键字:http://www.cnblogs.com/telnetz ...
- Java 泛型 Java使用泛型的意义
Java 泛型 Java使用泛型的意义 @author ixenos 直接意义 在编译时保证类型安全 根本意义 a) 类型安全问题源自可复用性代码的设计,泛型保证了类型安全的复用模板 b) 使用复用性 ...