打表找规律即可。

1,1,2,2,2,3,3,3,3,4,4,4,4,4...

注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关。

//#include<cstdio>
//#include<set>
//#include<cstring>
//using namespace std;
//bool vis[16];
//int n,SG[16][1<<16];
//int sg(int x,int moved)
//{
// if(SG[x][moved]!=-1)
// return SG[x][moved];
// set<int>S;
// for(int i=1;i<=x;++i)
// if(!((moved>>(i-1))&1))
// S.insert(sg(x-i,moved|(1<<(i-1))));
// for(int i=0;;++i)
// if(S.find(i)==S.end())
// return SG[x][moved]=i;
//}
//int main()
//{
// scanf("%d",&n);
// for(int i=1;i<=n;++i)
// {
// memset(SG,-1,sizeof(SG));
// printf("%d:%d\n",i,sg(i,0));
// }
// return 0;
//}
#include<cstdio>
using namespace std;
int sg[100],n,ans,e;
int main()
{
// freopen("e.in","r",stdin);
int x;
for(int i=1;;++i)
{
for(int j=1;j<=i+1;++j)
{
sg[++e]=i;
if(e==60)
goto OUT;
}
}
OUT:
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",&x);
ans^=sg[x];
}
puts(ans ? "NO" : "YES");
return 0;
}

【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones的更多相关文章

  1. 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...

  2. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

    C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...

  3. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  4. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

  5. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  6. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索

    A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch

    地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...

  8. 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define ...

  9. 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number

    发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...

随机推荐

  1. 2016广东工业大学校赛 D题 GDUT-oj1172

    Problem D: 二叉树的中序遍历 Description 对于学过数据结构的人来说,二叉树和二叉树上的中序遍历都是再简单不过的东西了.这道题就搞搞二叉树好了,当然,不是一般的二叉树:) 我们定义 ...

  2. 使用T4模板生成MySql数据库实体类

    注:本文系作者原创,但可随意转载. 现在呆的公司使用的数据库几乎都是MySQL.编程方式DatabaseFirst.即先写数据库设计,表设计按照规范好的文档写进EXCEL里,然后用公司的宏,生成建表脚 ...

  3. iOS 后台运行执行代码(例如定位)

  4. svn“Previous operation has not finished; run 'cleanup' if it was interrupted“ 或者不能cleanup,或者提示空目录 报错的解决方法

    参考了文档: http://blog.csdn.net/superch0054/article/details/38668017 今天碰到了个郁闷的问题,svn执行clean up命令时报错“Prev ...

  5. 图论:Stoer-Wagner算法

    利用Stoer-Wagner算法求无向图最小割 直接给出算法描述和过程实现: 算法步骤: . 设最小割cut=INF, 任选一个点s到集合A中, 定义W(A, p)为A中的所有点到A外一点p的权总和. ...

  6. 如何实现用户id生成一个唯一邀请码

    #如何实现用户id生成一个唯一邀请码 #创建验证码 function createCode($user_id) { static $source_string = 'E5FCDG3HQA4B1NOPI ...

  7. Spring - IoC(8): 基于 Annotation 的配置

    除了基于 XML 的配置外,Spring 也支持基于 Annotation 的配置.Spring 提供以下介个 Annotation 来标注 Spring Bean: @Component:标注一个普 ...

  8. bzoj3786 星际探索 splay dfs序

    这道题 首先 因为他求的是当前点到根节点的路径和 我们可以将题目转换为括号序列的写法 将点拆为左括号以及右括号 左括号为正 右括号为负 这样题目就变为了求前缀和了 如果一个点是这个点的子树 那么他的左 ...

  9. 谈数据中心SDN与NFV

    看到一篇谈论SDN与NFV的文章,分析的还不错,贴过来方便自己后续查阅: http://network.chinabyte.com/175/13095675.shtml 论数据中心SDN与NFV技术关 ...

  10. Django-models class Meta:元类

    Django模型之Meta选项详解 Model 元数据就是 "不是一个字段的任何数据" -- 比如排序选项, admin 选项等等.   Django模型类的Meta是一个内部类, ...