题目链接:https://vjudge.net/problem/POJ-1740#author=0

题意:有n堆石子,每次你可以选一堆拿走任意数量的石子,而且你还可以选择从这一堆剩下石子中取任意数量石子分配给其他堆,最后拿走石子的人获胜。

思路:我们先考虑如果有两堆石子一样的情况下,后手只要跟着先手取(如果先手还进行了分配,那么后手只要保证取完并且在分配后保证两堆还是一样的情况即可)这种情况下先后必败。那么我们就可以推广到有有数堆石子相同的情况下,先手也是必败。接下来考虑有奇数堆,那么先手只要把最多的一堆拿走然后进行分配使得剩下的偶数堆石子满足相等堆数有偶数组,这种情况下就是先手必胜,然后其余情况都是先手必败。

  1. 1 //#include <bits/stdc++.h>
  2. 2 #include <time.h>
  3. 3 #include <set>
  4. 4 #include <map>
  5. 5 #include <stack>
  6. 6 #include <cmath>
  7. 7 #include <queue>
  8. 8 #include <cstdio>
  9. 9 #include <string>
  10. 10 #include <vector>
  11. 11 #include <cstring>
  12. 12 #include <utility>
  13. 13 #include <cstring>
  14. 14 #include <iostream>
  15. 15 #include <algorithm>
  16. 16 #include <list>
  17. 17 using namespace std;
  18. 18 #define eps 1e-10
  19. 19 #define PI acos(-1.0)
  20. 20 #define lowbit(x) ((x)&(-x))
  21. 21 #define zero(x) (((x)>0?(x):-(x))<eps)
  22. 22 #define mem(s,n) memset(s,n,sizeof s);
  23. 23 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
  24. 24 typedef long long ll;
  25. 25 typedef unsigned long long ull;
  26. 26 const int maxn=2e5+5;
  27. 27 const int Inf=0x7f7f7f7f;
  28. 28 const ll mod=1e9+7;
  29. 29 //const int N=3e3+5;
  30. 30 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
  31. 31 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
  32. 32 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
  33. 33 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
  34. 34 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
  35. 35 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
  36. 36 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
  37. 37 int Abs(int n) {
  38. 38 return (n ^ (n >> 31)) - (n >> 31);
  39. 39 /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
  40. 40 若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
  41. 41 需要计算 n 和 -1 的补码,然后进行异或运算,
  42. 42 结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
  43. 43 }
  44. 44 ll binpow(ll a, ll b,ll c) {
  45. 45 ll res = 1;
  46. 46 while (b > 0) {
  47. 47 if (b & 1) res = res * a%c;
  48. 48 a = a * a%c;
  49. 49 b >>= 1;
  50. 50 }
  51. 51 return res%c;
  52. 52 }
  53. 53 void extend_gcd(ll a,ll b,ll &x,ll &y)
  54. 54 {
  55. 55 if(b==0) {
  56. 56 x=1,y=0;
  57. 57 return;
  58. 58 }
  59. 59 extend_gcd(b,a%b,x,y);
  60. 60 ll tmp=x;
  61. 61 x=y;
  62. 62 y=tmp-(a/b)*y;
  63. 63 }
  64. 64 ll mod_inverse(ll a,ll m)
  65. 65 {
  66. 66 ll x,y;
  67. 67 extend_gcd(a,m,x,y);
  68. 68 return (m+x%m)%m;
  69. 69 }
  70. 70 ll eulor(ll x)
  71. 71 {
  72. 72 ll cnt=x;
  73. 73 ll ma=sqrt(x);
  74. 74 for(int i=2;i<=ma;i++)
  75. 75 {
  76. 76 if(x%i==0) cnt=cnt/i*(i-1);
  77. 77 while(x%i==0) x/=i;
  78. 78 }
  79. 79 if(x>1) cnt=cnt/x*(x-1);
  80. 80 return cnt;
  81. 81 }
  82. 82 int main()
  83. 83 {
  84. 84 int n;
  85. 85 int a[101];
  86. 86 while(~scanf("%d",&n),n)
  87. 87 {
  88. 88 for(int i=1;i<=n;i++) cin>>a[i];
  89. 89 if(n%2) {puts("1");continue;}
  90. 90 else
  91. 91 {
  92. 92 int f=0;
  93. 93 sort(a+1,a+1+n);
  94. 94 for(int i=2;i<=n;i+=2)
  95. 95 {
  96. 96 if(a[i]!=a[i-1]) f=1;
  97. 97 }
  98. 98 if(f) puts("1");
  99. 99 else puts("0");
  100. 100 }
  101. 101 }
  102. 102 return 0;
  103. 103 }

A New Stone Game POJ - 1740的更多相关文章

  1. POJ 1740 A New Stone Game(博弈)题解

    题意:有n个石子堆,每一个都可以轮流做如下操作:选一个石堆,移除至少1个石子,然后可以把这堆石子随便拿几次,随便放到任意的其他石子数不为0的石子堆,也可以不拿.不能操作败. 思路:我们先来证明,如果某 ...

  2. POJ 1740 A New Stone Game

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5453   Accepted: 2989 ...

  3. poj 1740 A New Stone Game(博弈)

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5338   Accepted: 2926 ...

  4. POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律

    http://poj.org/problem?id=1740 这个博弈一眼看上去很厉害很高大上让人情不自禁觉得自己不会写,结果又是找规律…… 博弈一般后手胜都比较麻烦,但是主要就是找和先手的对应关系, ...

  5. POJ 1740 A New Stone Game(普通博弈)

    A New Stone Game 题意: 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输 ...

  6. 博弈论(男人八题):POJ 1740 A New Stone Game

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5694   Accepted: 3119 ...

  7. POJ 1740:A New Stone Game

    A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5113 Accepted: 2806 Desc ...

  8. [原博客] POJ 1740 A New Stone Game

    题目链接题意:有n堆石子,两人轮流操作,每次每个人可以从一堆中拿走若干个扔掉(必须),并且可以从中拿走一些分到别的有石子的堆里(可选),当一个人不能拿时这个人输.给定状态,问是否先手必胜. 我们参考普 ...

  9. POJ 1740 A New Stone Game(多堆博弈找规律)

    传送门 //有n堆,AB轮流从n堆的一堆中移任意个,可以扔掉,也可以移给其他堆中的一堆 //最先移完的胜 //如果n堆中两两堆数目相等,那肯定是B胜 //但只要有非两两相同的,如xyz,A先, //A ...

随机推荐

  1. 正则表达式 test 踩坑指南

    正则表达式 test 踩坑指南 test 只能使用一次,第二次返回的是错误结果! reg = /edg|edge/g; /edg|edge/g reg.test(`edg`) true reg.tes ...

  2. config file language All In One

    config file language All In One YAML YAML Ain't Markup Language .yaml / .yml https://yaml.org/ https ...

  3. cocos2d-x & cocos2d-js

    cocos2d-x & cocos2d-js cocos2d-x new https://github.com/cocos2d/cocos2d-x cocos2d-x is a multi-p ...

  4. CSS transition & shorthand property order

    CSS transition & shorthand property order shorthand property https://developer.mozilla.org/en-US ...

  5. Base 64 & URL & blob & FileReader & createObjectURL

    Base 64 & URL & blob & FileReader & createObjectURL /** * let blob = item.getAsFile( ...

  6. Android混合Flutter

    官方文档 实验性:将Flutter添加到Android 测试仓库 取决于模块的源代码 方法测试成功

  7. NGK推出SPC算力币,开启算力新玩法!

    这两天,NGK公链再度上了热搜.因为既成功的打造DeFi生态以后,NGK又将目光对准了算力市场.试图通过算力代币化,让NGK算力持有者可以获得算力代币,同时,如果不想要了,算力持有者也可以抛售代币. ...

  8. 深入浅出的JS执行机制(图文教程)

    前序 作为一个有理想有抱负的前端攻城狮,想要走向人生巅峰,我们必须将我们使用的功法练到天人合一的地步.我在们日常工作中,使用最多的语言就是JavaScript了,为了写出完美的.能装逼的代码,我们必须 ...

  9. SpringBoot整合Mybatis 使用generator自动生成实体类代码、Mapper代码、dao层代码

    1.新建一个SpringBoot项目,并引入Mybatis和mybatis-generator相关的依赖. <dependency> <groupId>org.springfr ...

  10. Vue中Jsx的使用

    什么是JSX? JSX就是Javascript和XML结合的一种格式.React发明了JSX,利用HTML语法来创建虚拟DOM.当遇到<,JSX就当HTML解析,遇到{就当JavaScript解 ...