MUV LUV UNLIMITED(ccpc 秦皇岛2019)

题目描述

There are few entertainments in United Nations 11th Force, Pacific Theater, Yokohama base, the only pastime for squad 207 is gathering in PX to play games after supper. However, whatever they play, Shirogane Takeru is always the loser. So he decides to use the game theory knowledge from
another world to become the winner. According to the knowledge he has learnt, Takeru introduces his army friends a game:
Given a rooted tree of size n, whose root is vertex 1. Two players do operations on the tree alternately.
In each operation, a player should choose several (at least one) leaf vertices (which have no children vertices) and remove them from the tree. As can be seen, there might be some new leaf vertices after one operation. The player who cannot make a move in his/her turn loses the game.
But unfortunately, Takeru doesn’t master the knowledge skillfully, so he has no idea whether the first player will win if the two players are playing optimally. Please help him determine that.
Assume that the two players are playing optimally to make themselves win, print “Takeru” in a single line if the first player will win, or print “Meiya” otherwise.

输入

The first line contains one positive integer T, denoting the number of test cases.
For each test case:
The first line contains one positive integer n (2 ≤ n ≤ 10 6), denoting the size of the given tree.
The next line contains n − 1 positive integers pi (1 ≤ pi ≤ n), where i-th integer denotes the parent vectex of vectex i + 1.
It is guaranteed that the sum of n among all cases in one test file does not exceed 10 6.

输出

Output T lines each contains a string “Takeru” or “Meiya”, denoting the answer to corresponding test case.

样例输入

复制样例数据

2
3
1 1
4
1 2 3

样例输出

Takeru
Meiya

提示

For the first case, the first player can remove vertex 3 firstly. As a result, the second player has no choice but to remove vertex 2. Finally, the first player removes vertex 1 and becomes the winner.
For the second case, the two players can only remove exactly one vertex in each operation alternately.
As can be seen, the winner, who removes vertex 1, will be the second player.

ps;题意:给你一棵树,每次可以删去叶子节点(任意数量),不能删就输了。明显一条链 奇数必胜,偶数必败。

其次,如果存在长度为1的枝条,先手必胜。

为什么???

是否删除这个点取决于 删后 对手是什么状态,可以根据删后的状态决定是否删除,画几个图想一想。

如果所有的枝条都是偶数,则必败,无论怎么删,对手都可以删回全偶数的状态。

所以这个题先找到每个枝条,看是否存在奇数长度的枝条就可以了。

关于怎么求枝条的长度,从叶子节点,找父亲,父亲的度必小于等于1.

代码如下:

#pragma GCC optimize(3 , "Ofast" , "inline")#include <iostream>
#include <bits/stdc++.h>using namespace std;
const int N = 1000005;int n;
int deg[N] , dep[N];void init () {for ( register int i = 0 ; i <= n ; i ++ ) dep[ i ] = deg[ i ] = 0;
}int main () {int T;scanf ("%d" , &T);while (T --) {scanf ("%d" , &n);for ( register int i = 2 ; i <= n ; i ++ ) {int p;scanf ("%d" , &p);deg[ p ] ++;dep[ i ] = p;}bool f = 0;for ( register int i = 1 ; i <= n ; i ++ ) {int cnt = 0;if ( deg[ i ] == 0 ) {int u = i;while (u != 0 && deg[ u ] <= 1) {cnt ++;u = dep[ u ];}if ( cnt & 1 ) {f = 1;break;}}}if ( f ) {printf ("Takeru\n");} else {printf ("Meiya\n");}init ();}return 0;
}

http://www.taodudu.cc/news/show-7074314.html

相关文章:

  • CodeForces 663A Rebus
  • HDU1686——Oulipo
  • ERROR: torch-1.4.0+cpu-cp38-cp38m-win_amd64.whl is not a supported wheel on this platform.
  • 665PB1F、665PB2F、665PB5F驱动液压伺服马达
  • I420到UYVY的转换
  • YUV420转YUV444
  • ERROR: torch-1.12.0+cu116-cp38-cp38-win_amd64.whl is not a supported wheel on this platform.
  • ERROR: mmcv_full-1.4.0-cp38-cp38-win_amd64.whl is not a supported wheel on this platform.
  • 【机器学习】ID3_C4.5_CART算法总结与对比
  • 你知道这11个重要的机器学习模型评估指标吗?
  • 【baseline】Kaggle新赛!信用违约预测大赛
  • 模式识别:让数据说话,让机器决策
  • 【零基础学机器学习 10】随机森林算法最佳指南以及代码实战
  • 备战数学建模43-决策树随机森林Logistic模型(攻坚站7)
  • 教练,我想学设计之禅
  • AD20过孔设置-4层板
  • 使用AD18 敷铜时,不显示敷铜的板框,
  • 厨卫装修如何选择铝扣板
  • 垫片落料冲孔复合模设计(说明书+CAD图纸+PROE三维+SolidWorks+答辩ppt)
  • 第06章 空间钢架结构(简支梁),(四点吊装)的深入分析及拓展
  • 旅游APP设计与实现
  • 微信小程序 旅游景点酒店预订管理系统pcAndroid hbuilderx App毕业设计
  • 基于Android Studio开发的旅游记录与分享APP源码,Android旅游路线记录与分享APP源码
  • 基于Android的乡镇旅游指南APP-景点-酒店预订系统
  • 基于Android的旅游助手app酒店景点预订系统
  • Android旅游景点美食点评系统app
  • 听音乐
  • C语言怎样播放音乐
  • Android Car音乐播放器分析
  • python周末培训班 上海哪个最好

MUV LUV UNLIMITED(ccpc 秦皇岛2019)相关推荐

  1. 2019 China Collegiate Programming Contest Qinhuangdao K. MUV LUV UNLIMITED

    MUV LUV UNLIMITED Link 题目大意:给出一棵树,两人轮流任取(至少取一)当前树上的叶子,最先不能操作的人输. 首先考虑一个情况,若一个叶子节点 x x x 有兄弟,则先手必胜.因为 ...

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

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

  3. MUV LUV EXTRA 2019CCPC秦皇岛站J

    MUV LUV EXTRA 2019CCPC秦皇岛站J (hdu重现赛) 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6740 思路 kmp求循环节 ...

  4. K. MUV LUV UNLIMITED(树上博弈)

    原题链接:K. MUV LUV UNLIMITED 题意: 给你一棵 n 个点以 1 为根的有根树.现在有两个人轮流操作,每次操作人可以选出至少1个叶子(没有儿子的点)删掉,无法操作的人失败.二者都是 ...

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

    2019CCPC秦皇岛K 题意: 两个人玩游戏, 有一棵有根树,每次只能拿叶子节点若干个(不能不拿),问最后谁会赢 思路: 先说结论,数每个叶子节点对应上去的那条链(直到他的父亲除自己外有另外的儿子结 ...

  6. 2019CCPC秦皇岛 K MUV LUV UNLIMITED(思维博弈)

    2019CCPC秦皇岛K 这个题感觉就是头脑风暴吧,关键在于抓住正确的方向想下去,我中间也跑偏了几次... 定义一个分支为从叶子往根的方向,不存在包含多个子节点的节点序列,即从叶子到包含多个子节点的节 ...

  7. 2019ccpc秦皇岛赛区K. MUV LUV UNLIMITED(博弈)

    题目连接 题意:两个人在一棵树上玩游戏,两人轮流在树上选择一个以上的叶子进行删除.最后删掉根节点的人获胜,问是先手必胜还是后手必胜 (1).若只有一条链,则直接判奇偶(废话) (2).若不只一条链,则 ...

  8. MUV LUV EXTRA 2019CCPC秦皇岛站J题 KMP

    题目链接 题意:意思给你俩数一个字符串,然后让你对字符串小数点后边的字符串进行处理,找个一个循环节以及对应出现的长度, 然后用a*p-b*l算得到一个最大值 那肯定循环节就想到了KMP了,然后循环长度 ...

  9. HDU 6741 MUV LUV UNLIMITED (博弈论)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6741 题解 看完题解深刻地意识到自己是个智障. (1) 如果某个叶子节点的父亲有多于一个儿子,则为必胜 ...

最新文章

  1. ORB_SLAM2代码阅读(1)——系统入口
  2. 解析:GE工业互联网平台Predix
  3. MemSQL初体验 - (3)性能测试
  4. RabbitMQ简介和六种工作模式详解
  5. 避开10个面试大坑,接offer成功率提升至99%
  6. Flume监听文件夹中的文件变化_并把文件下沉到hdfs
  7. “拼图”化解智慧城市“碎片化”难题
  8. 思科2960g端口限速配置
  9. 十代主板改win7_10代cpu装win7系统及bios设置教程(完美支持10代驱动)
  10. mtkwin10驱动_MTK手机刷机驱动下载|MTK通用USB刷机驱动 Win7/Win10 自动安装版 下载_当下软件园_软件下载...
  11. Python 微信自动化工具开发系列05_根据用户信息自动回复(2022年10月可用)
  12. 用flash做古诗动画_Flash制作跟我学 用遮罩技术制作古诗动画-FLASH课件制作(FLASH课件制作教程)-flash课件吧(湖北金鹰)...
  13. yylabel html不显示图片,YYLabel富文本
  14. 如何查看当前位置显存使用情况
  15. The server returned the following error: 无法与服务器建立连接(0x80072EFD)
  16. 微信企业号开发-如何建立连接
  17. ajax——请求消息(request)和响应消息(response)
  18. 突然断电对oracle的影响吗,当ORACLE突然断电,重新启动过程发生了哪些事?
  19. [svn] TortoisSVN的Blam功能
  20. HDU - 1686 Oulipo

热门文章

  1. All in AI?(下)
  2. WackoPicko安装教程
  3. emqttd的启动脚本
  4. java jettison_Java常用Json库性能对比
  5. 张一鸣做手机,没那么简单
  6. 以爱之名,ivvi在下一盘大棋
  7. 花些时间把python入门——python、vscode、廖雪峰
  8. 多版本cuda安装及灵活切换详细教程
  9. poi 解析中文_百度地图周边最近的POI查询并且解析出中文地址
  10. 简述PRIMARY KEY与identity(1,1)的含义