Problem G: Game of Cards

\[Time Limit: 1 s \quad Memory Limit: 256 MiB
\]

题意

题意就是给出\(n\)堆扑克牌,然后给出一个\(m\),每次一个人的操作方法是从一堆扑克牌上面选出\(0-m\)张牌拿开,然后此时顶上牌的点数是\(x\),在拿开\(x\)张牌,最后不能操作的人输。

思路

就是一个裸的\(sg\)函数,用dfs比较好写,然后直接模拟就可以了。

  1. /***************************************************************
  2. > File Name : G.cpp
  3. > Author : Jiaaaaaaaqi
  4. > Created Time : 2019年05月06日 星期一 18时04分27秒
  5. ***************************************************************/
  6. #include <map>
  7. #include <set>
  8. #include <list>
  9. #include <ctime>
  10. #include <cmath>
  11. #include <stack>
  12. #include <queue>
  13. #include <cfloat>
  14. #include <string>
  15. #include <vector>
  16. #include <cstdio>
  17. #include <bitset>
  18. #include <cstdlib>
  19. #include <cstring>
  20. #include <iostream>
  21. #include <algorithm>
  22. #define lowbit(x) x & (-x)
  23. #define mes(a, b) memset(a, b, sizeof a)
  24. #define fi first
  25. #define se second
  26. #define pii pair<int, int>
  27. #define INOPEN freopen("in.txt", "r", stdin)
  28. #define OUTOPEN freopen("out.txt", "w", stdout)
  29. typedef unsigned long long int ull;
  30. typedef long long int ll;
  31. const int maxn = 1e3 + 10;
  32. const int maxm = 1e5 + 10;
  33. const ll mod = 1e9 + 7;
  34. const ll INF = 1e18 + 100;
  35. const int inf = 0x3f3f3f3f;
  36. const double pi = acos(-1.0);
  37. const double eps = 1e-8;
  38. using namespace std;
  39. int n, m, k;
  40. int cas, tol, T;
  41. int a[maxn];
  42. ll sg[maxn];
  43. void dfs(int x) {
  44. if(sg[x] != -1) return ;
  45. vector<bool> vis(maxn, false);
  46. for(int i=0; i<=m; i++) {
  47. int up = x-i;
  48. if(up <= 0) break;
  49. int nxt = up - a[up];
  50. if(nxt < 0) continue;
  51. dfs(nxt);
  52. vis[sg[nxt]] = true;
  53. }
  54. for(int i=0; ; i++) {
  55. if(!vis[i]) {
  56. sg[x] = i;
  57. return ;
  58. }
  59. }
  60. }
  61. int main() {
  62. scanf("%d%d", &T, &m);
  63. ll ans = 0;
  64. while(T--) {
  65. scanf("%d", &n);
  66. mes(a, 0);
  67. mes(sg, -1);
  68. a[0] = sg[0] = 0;
  69. for(int i=1; i<=n; i++) {
  70. scanf("%d", &a[i]);
  71. }
  72. dfs(n);
  73. ans ^= sg[n];
  74. }
  75. if(ans)
  76. printf("Alice can win.\n");
  77. else
  78. printf("Bob will win.\n");
  79. return 0;
  80. }

Game of Cards Gym - 101128G (SG函数)的更多相关文章

  1. UVALive 7278 Game of Cards (sg函数)

    Game of Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/G Description Alice and Bob ...

  2. LA 7278 Game of Cards(SG函数)

    https://vjudge.net/problem/UVALive-7278 题意: 两个人玩游戏,现在有n堆牌,轮到自己时,先在牌堆中选一堆牌,先在牌堆中选择拿走0~k张牌(至少得剩下一张),然后 ...

  3. 【博弈论】【SG函数】【找规律】Gym - 101147A - The game of Osho

    以后这种题还是不能空想,必须打个表看看,规律还是比较好找的……具体是啥看代码.用SG函数暴力的部分就不放了. #include<cstdio> using namespace std; i ...

  4. codeforce Gym 100500E IBM Chill Zone (SG函数)

    关于sg函数这篇blog讲得很详细http://blog.csdn.net/logic_nut/article/details/4711489. sg函数的价值在于把复杂的游戏拆分成简单的游戏,然后通 ...

  5. gym/102059/problem/I. Game on Plane SG函数做博弈

    传送门: 题意: 给定一个正n边形的点.双方轮流连点成线,要求所画的线不能与之前的线相交.当某个人连成一个回路,这个人就输了.问先手必胜还是后手必胜. 思路: SG函数,因为一条线相当于把图劈成了两半 ...

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

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

  7. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

  8. HDU 1848 Fibonacci again and again【SG函数】

    对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...

  9. POJ2425 A Chess Game[博弈论 SG函数]

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Desc ...

随机推荐

  1. JMeter一台机器可以支持多大的并发量

    Support for concurrent thread is basically depends on many factors like OS, free RAM and connections ...

  2. Effective.Java第56-66条(规范相关)

    56.  为所有已公开的API元素编写文档注释 要正确地记录API,必须在每个导出的类.接口.构造方法.方法和属性声明之前加上文档注释.如果一个类是可序列化的,还需要记录它的序列化形式. 文档注释在源 ...

  3. npm install 报错 error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,"d' 解决办法

    npm install 报错 : error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,& ...

  4. play framework + sbt入门之环境搭建

    一 sbt的使用 SBT = (not so) Simple Build Tool,是scala的构建工具,与java的maven地位相同.其设计宗旨是让简单的项目可以简单的配置,而复杂的项目可以复杂 ...

  5. python面试题_01

    前言 现在面试测试岗位,一般会要求熟悉一门语言(python/java),为了考验求职者的基本功,一般会出2个笔试题,这些题目一般不难,主要考察基本功.要是给你一台电脑,在编辑器里面边写边调试,没多大 ...

  6. Redis 获取和设置密码

    1.config get reuqirepass //获取当前密码 2.config set requirepass "password"//设置当前密码,双引号里面为密码

  7. C#读写调整设置UVC摄像头画面-亮度

    有时,我们需要在C#代码中对摄像头的亮度进行读和写,并立即生效.如何实现呢? 建立基于SharpCamera的项目 首先,请根据之前的一篇博文 点击这里 中的说明,建立基于SharpCamera的摄像 ...

  8. Throwable中几个常见方法。

    getMessage();//获取异常信息,返回字符串.例如: toString();//获取异常类名和异常信息,返回字符串.例如: printStackTrace();//获取异常类名和异常信息,以 ...

  9. Java自学-类和对象 包

    Java中的 包 包: package 把比较接近的类,规划在同一个包下 步骤 1 : 把比较接近的类,规划在同一个包下 Hero,ADHero 规划在一个包,叫做charactor(角色) Item ...

  10. Scheduling Tasks

    官方文档 https://spring.io/guides/gs/scheduling-tasks/ 官方文档详细介绍了@Scheduled中fixedRate,fixedDelay,cron的用法 ...