打表找规律即可。

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

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

  1. //#include<cstdio>
  2. //#include<set>
  3. //#include<cstring>
  4. //using namespace std;
  5. //bool vis[16];
  6. //int n,SG[16][1<<16];
  7. //int sg(int x,int moved)
  8. //{
  9. // if(SG[x][moved]!=-1)
  10. // return SG[x][moved];
  11. // set<int>S;
  12. // for(int i=1;i<=x;++i)
  13. // if(!((moved>>(i-1))&1))
  14. // S.insert(sg(x-i,moved|(1<<(i-1))));
  15. // for(int i=0;;++i)
  16. // if(S.find(i)==S.end())
  17. // return SG[x][moved]=i;
  18. //}
  19. //int main()
  20. //{
  21. // scanf("%d",&n);
  22. // for(int i=1;i<=n;++i)
  23. // {
  24. // memset(SG,-1,sizeof(SG));
  25. // printf("%d:%d\n",i,sg(i,0));
  26. // }
  27. // return 0;
  28. //}
  29. #include<cstdio>
  30. using namespace std;
  31. int sg[100],n,ans,e;
  32. int main()
  33. {
  34. // freopen("e.in","r",stdin);
  35. int x;
  36. for(int i=1;;++i)
  37. {
  38. for(int j=1;j<=i+1;++j)
  39. {
  40. sg[++e]=i;
  41. if(e==60)
  42. goto OUT;
  43. }
  44. }
  45. OUT:
  46. scanf("%d",&n);
  47. for(int i=1;i<=n;++i)
  48. {
  49. scanf("%d",&x);
  50. ans^=sg[x];
  51. }
  52. puts(ans ? "NO" : "YES");
  53. return 0;
  54. }

【博弈论】【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. Angular 遍历循环数组

    var app = angular.module('Mywind',['ui.router']) app.controller('Myautumn',function($scope,$http,$fi ...

  2. Clevo P950系列拆机

    Clevo P950系列(包括神舟精盾T96/T97/T96C/T96E/T97E,炫龙耀9000,铁头人T800同模具机型)拆机 拆机恢复时间:20181203 12:28-14:58   一.普通 ...

  3. Array.slice(start,end)的用法

    start在start>=0,假设start=0,表示从数组的第一个元素开始截取,start=2,表示从数组的第二个元素开始截取,依次类推. 在start<0时,start=-1表示从倒数 ...

  4. Java并发(6)- CountDownLatch、Semaphore与AQS

    引言 上一篇文章中详细分析了基于AQS的ReentrantLock原理,ReentrantLock通过AQS中的state变量0和1之间的转换代表了独占锁.那么可以思考一下,当state变量大于1时代 ...

  5. java中的构造块、静态块等说明

    一:这篇博客写的时候我在学校已经一个星期了,为什么又会想到写这le,因为这几天又在重新学下有关spring.myBatis的知识,其中在实例化sessionFactory的时候用到了静态块,虽然在学习 ...

  6. TCP(一)

    TCP的特点:三次握手.四次挥手.可靠连接.丢包重传.所有的关键词都围绕着可靠传输. 实现可靠传输的核心机制:seq+ack.通过ack判断是否有丢包,是否需要重传. 三次握手 1)初始状态:clie ...

  7. Spring学习之路——单例模式和多例模式

    在Spring中,bean可以被定义为两种模式:prototype(多例)和singleton(单例) singleton(单例):只有一个共享的实例存在,所有对这个bean的请求都会返回这个唯一的实 ...

  8. 【uva10829-求形如UVU的串的个数】后缀数组+rmq or 直接for水过

    题意:UVU形式的串的个数,V的长度规定,U要一样,位置不同即为不同字串 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&am ...

  9. 【HDU3853】LOOPS [期望DP]

    LOOPS Time Limit: 5 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description Akemi Homura is a ...

  10. xampp命令

    XAMPP命令安装 XAMPPtar xvfz xampp-linux-1.6.4.tar.gz -C /opt启动 XAMPP/opt/lampp/lampp start停止 XAMPP/opt/l ...