题目链接:https://vjudge.net/problem/Gym-102361K

题意:两个人轮流取树叶,最后没有树叶取的人输。

思路:求出所有树叶所在链的长度即可,如果都为偶数先手必败,否则先手必胜。

  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 //cout<<setprecision(10)<<fixed;
  19. 19 #define eps 1e-6
  20. 20 #define PI acos(-1.0)
  21. 21 #define lowbit(x) ((x)&(-x))
  22. 22 #define zero(x) (((x)>0?(x):-(x))<eps)
  23. 23 #define mem(s,n) memset(s,n,sizeof s);
  24. 24 #define rep(i,a,b) for(int i=a;i<=b;i++)
  25. 25 #define rep2(i,a,b) for(int i=a;i>=b;i--)
  26. 26 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
  27. 27 typedef long long ll;
  28. 28 typedef unsigned long long ull;
  29. 29 const int maxn=1e6+5;
  30. 30 const ll Inf=0x7f7f7f7f7f7f7f7f;
  31. 31 const ll mod=1e6+3;
  32. 32 //const int N=3e3+5;
  33. 33 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
  34. 34 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
  35. 35 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
  36. 36 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
  37. 37 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
  38. 38 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
  39. 39 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
  40. 40 inline int read()
  41. 41 {
  42. 42 int X=0; bool flag=1; char ch=getchar();
  43. 43 while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
  44. 44 while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
  45. 45 if(flag) return X;
  46. 46 return ~(X-1);
  47. 47 }
  48. 48 inline void write(int X)
  49. 49 {
  50. 50 if(X<0) {X=~(X-1); putchar('-');}
  51. 51 if(X>9) write(X/10);
  52. 52 putchar(X%10+'0');
  53. 53 }
  54. 54 /*
  55. 55 inline int write(int X)
  56. 56 {
  57. 57 if(X<0) {putchar('-'); X=~(X-1);}
  58. 58 int s[20],top=0;
  59. 59 while(X) {s[++top]=X%10; X/=10;}
  60. 60 if(!top) s[++top]=0;
  61. 61 while(top) putchar(s[top--]+'0');
  62. 62 }
  63. 63 */
  64. 64 int Abs(int n) {
  65. 65 return (n ^ (n >> 31)) - (n >> 31);
  66. 66 /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
  67. 67 若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
  68. 68 需要计算 n 和 -1 的补码,然后进行异或运算,
  69. 69 结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
  70. 70 }
  71. 71 ll binpow(ll a, ll b) {
  72. 72 ll res = 1;
  73. 73 while (b > 0) {
  74. 74 if (b & 1) res = res * a%mod;
  75. 75 a = a * a%mod;
  76. 76 b >>= 1;
  77. 77 }
  78. 78 return res%mod;
  79. 79 }
  80. 80 void extend_gcd(ll a,ll b,ll &x,ll &y)
  81. 81 {
  82. 82 if(b==0) {
  83. 83 x=1,y=0;
  84. 84 return;
  85. 85 }
  86. 86 extend_gcd(b,a%b,x,y);
  87. 87 ll tmp=x;
  88. 88 x=y;
  89. 89 y=tmp-(a/b)*y;
  90. 90 }
  91. 91 ll mod_inverse(ll a,ll m)
  92. 92 {
  93. 93 ll x,y;
  94. 94 extend_gcd(a,m,x,y);
  95. 95 return (m+x%m)%m;
  96. 96 }
  97. 97 ll eulor(ll x)
  98. 98 {
  99. 99 ll cnt=x;
  100. 100 ll ma=sqrt(x);
  101. 101 for(int i=2;i<=ma;i++)
  102. 102 {
  103. 103 if(x%i==0) cnt=cnt/i*(i-1);
  104. 104 while(x%i==0) x/=i;
  105. 105 }
  106. 106 if(x>1) cnt=cnt/x*(x-1);
  107. 107 return cnt;
  108. 108 }
  109. 109 int fa[maxn],son[maxn];
  110. 110 int n;
  111. 111 int main()
  112. 112 {
  113. 113 int t=read();
  114. 114 while(t--)
  115. 115 {
  116. 116 n=read();
  117. 117 for(int i=2;i<=n;i++)
  118. 118 {
  119. 119 fa[i]=read();
  120. 120 son[fa[i]]++;
  121. 121 }
  122. 122 bool ans=0;
  123. 123 for(int i=1;i<=n;i++)
  124. 124 {
  125. 125 if(son[i]==0)
  126. 126 {
  127. 127 if(son[fa[i]]>1) {ans=true;break;}
  128. 128 int cnt=1;
  129. 129 for(int u=i;son[fa[u]]==1;u=fa[u]) cnt++;
  130. 130 if(cnt&1) {ans=true;break;}
  131. 131 }
  132. 132 }
  133. 133 puts(ans?"Takeru":"Meiya");
  134. 134 for(int i=1;i<=n;i++) fa[i]=son[i]=0;
  135. 135 }
  136. 136 return 0;
  137. 137 }

MUV LUV UNLIMITED Gym - 102361K的更多相关文章

  1. 2019CCPC秦皇岛 K MUV LUV UNLIMITED(博弈)

    MUV LUV UNLIMITED Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  2. 2019CCPC秦皇岛 J MUV LUV EXTRA(KMP)

    MUV LUV EXTRA Time Limit: 2000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  3. 【2019 CCPC 秦皇岛】J - MUV LUV EXTRA

    原题: 题意: 给你两个整数a和b,再给你一个正小数,整数部分忽略不计,只考虑小数部分的循环节,对于所有可能的循环节,令其长度为l,在小数部分循环出现的长度为p,最后一个循环节允许不完整,但是缺少的部 ...

  4. HDU6740 2019CCPC秦皇岛赛区 J. MUV LUV EXTRA

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6740思路:求小数部分后k位的真前后缀 倒着kmp就好 #include<bits/stdc++.h& ...

  5. 2019 China Collegiate Programming Contest Qinhuangdao Onsite

    传送门 D - Decimal 题意: 询问\(\frac{1}{n}\)是否为有限小数. 思路: 拆质因子,看是不是只包含2和5即可,否则除不尽. Code #include <bits/st ...

  6. 2019-ccpc秦皇岛现场赛

    https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...

  7. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  8. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  9. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

随机推荐

  1. Makefile 赋值 函数定义 等小知识点

    1.赋值 == 到用的时候实际才去赋值:= 立刻赋值?= 未赋值才赋值+= 2.多层变量 多层变量引用(各种复杂组合...)a =bb= cc= dd =1$($($($(a)))) 最终等于1 3. ...

  2. Linux bash script regex auto replace

    Linux bash script regex auto replace 自动替换 /assets/css/0.styles.96df394b.css => ./assets/css/0.sty ...

  3. CSS hover box

    CSS hover box transition 踩坑指南, display: none; 作为初始状态,不会产生动画效果,必须设置 height: 0; 或 width: 0; 来实现隐藏! tra ...

  4. TypeScript callback Object params

    TypeScript callback Object params 回调函数 对象 参数 const func = (options = {}) => { // do somthing retu ...

  5. 微信小程序批量上传图片 All In One

    微信小程序批量上传图片 All In One open-data https://developers.weixin.qq.com/miniprogram/dev/component/open-dat ...

  6. CORS All In One

    CORS All In One 跨域资源共享 https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS CORS 请求类型 简单请求 预检请求 Ac ...

  7. website captcha

    website captcha 验证码 hCaptcha hCaptcha通过询问对人类来说很容易且对机器来说很困难的简单问题,可以帮助您喜欢的Web服务阻止机器人,垃圾邮件和滥用行为. https: ...

  8. 如何通过NGK数字增益平台实现兑换算力

    最近币圈里有一个新项目NGK非常火热,很多朋友在经过了了解以后纷纷表示很看好这个项目,那么除了二级市场之外,是否还能有其他的方式可以更低成本地获得NGK代币呢? 答案是肯定的,NGK数字增益平台便是低 ...

  9. Baccarat流动性挖矿是如何改进自动化做市商的痛点的?

    Baccarat自上线至今已经有两个多月的时间,尤其代币BGV引来了无数投资者的注意.同时也有越来越多的投资者开始关注到Baccarat本身,Baccarat采取的AMM机制,与其他的DeFi项目所采 ...

  10. uniapp 自定义弹窗组件

    先上效果: 组件源码:slot-modal.vue <template> <view class="modal-container" v-if="sho ...