Gameia
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 935 Accepted Submission(s): 403

Problem Description
Alice and Bob are playing a game called ‘Gameia ? Gameia !’. The game goes like this :
0. There is a tree with all node unpainted initial.
1. Because Bob is the VIP player, so Bob has K chances to make a small change on the tree any time during the game if he wants, whether before or after Alice’s action. These chances can be used together or separate, changes will happen in a flash. each change is defined as cut an edge on the tree.
2. Then the game starts, Alice and Bob take turns to paint an unpainted node, Alice go first, and then Bob.
3. In Alice’s move, she can paint an unpainted node into white color.
4. In Bob’s move, he can paint an unpainted node into black color, and what’s more, all the other nodes which connects with the node directly will be painted or repainted into black color too, even if they are white color before.
5. When anybody can’t make a move, the game stop, with all nodes painted of course. If they can find a node with white color, Alice win the game, otherwise Bob.
Given the tree initial, who will win the game if both players play optimally?

Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with two integers N and K : the size of the tree and the max small changes that Bob can make.
The next line gives the information of the tree, nodes are marked from 1 to N, node 1 is the root, so the line contains N-1 numbers, the i-th of them give the farther node of the node i+1.

Limits
T≤100
1≤N≤500
0≤K≤500
1≤Pi≤i

Output
For each test case output one line denotes the answer.
If Alice can win, output “Alice” , otherwise “Bob”.

Sample Input
2
2 1
1
3 1
1 2

Sample Output
Bob
Alice

题目大意:

A和B两个人玩游戏,A先手,B后手,A每一次操作可以选择任意一个没有染色的点,将其染色为白色。B每一次操作可以选择任意一个没有染色的点,将其染成黑色,并且这个点直接相连的所有点都变成黑色(即使是白色也会被染成黑色)。因为B玩家是VIP玩家,所以他有K次机会拆边,当没有人可以进行操作的时候,游戏结束,当还存在白色点的时候,A赢,否则B赢。

官方博客:
如果Bob能把这棵树分成若干两个一组的点对,那么Bob取得胜利,否则Alice获胜。

如果原树不存在两两匹配的方案,Alice从树叶开始,每次都染树叶父节点,Bob被迫只能不断的染叶子,
Bob退化成一般玩家,因为Bob做不做小动作都不会逆转局势,总会出现一个时间点Bob没办法跟上Alice的节奏而让Alice染到一个周围都已被染色的孤立点(因为原树不存在两两匹配的方案)

如果原树存在两两匹配的方案,而且Bob的小动作次数也足以把原树分成两两的点对,那么Bob显然获胜。

如果原树存在两两匹配的方案,而Bob的小动作不足以把树分成两两的点对,Alice一定获胜,因为每次染某个叶子节点(该节点为其父节点的唯一子节点),Alice总能迫使Bob不断的做小动作以保证剩下的树不会出现奇数节点的树,且每次小动作割出一个点对(包含Alice刚染的点),最后有两种情况。
出现某个结点有>=2个子节点为叶子节点。Alice染这个点,Bob跟不上Alice的节奏,出现孤点,Ailice取胜
否则整个过程一定会持续到树被染光或者Bob被Alice掏空导致做不了小动作进而被迫割出一块size为奇数的子树(这棵树显然没办法两两匹配)而败北。

Bob被允许“任意时刻”做小动作看似很厉害其实很鸡肋,把问题改成“Bob只能在游戏开始之前做小动作”会得到同样的结论。
“氪不改命,玄不救非”

#include<bits/stdc++.h>
using namespace std;
#define maxn 555
int par[maxn];
vector<int> v[maxn];
bool vis[maxn];bool flag;
int dfs(int rt)
{int z=0;for(int i=0;i<v[rt].size();i++){z+=dfs(v[rt][i]);if(z>=2) flag=false;}if(v[rt].size()==0) return 1;return 0;
}int main()
{int t,n,k,p;cin>>t;while(t--){memset(vis,0,sizeof(vis));scanf("%d",&n);scanf("%d",&k);for(int i=0;i<=n;i++) v[i].clear();par[1]=0;flag=true;for(int i=2;i<=n;i++){scanf("%d",&p);par[i]=p;v[p].push_back(i);}dfs(1);if(n%2==0&&flag&&n/2-1<=k)cout<<"Bob"<<endl;else cout<<"Alice"<<endl;}
}

Gameia HDU 6105相关推荐

  1. HDU 6105 Gameia 树上博弈(思路题)(内附官方题解)

    题目  :Gameia:链接 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  2. hdu 6015 Gameia(树上博弈)

    题目链接:hdu 6015 Gameia 题意: 给出一棵树,Alice 和 Bob 轮流操作, Alice先手, Alice的操作是选一个未染色的点将其染成白色,Bob的操作是选一个未染色的点将其染 ...

  3. HDU 4389 - X mod f(x)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4389 2012多校,第9场,1010 . 问题是,询问区间内 存在多少个 哈沙德数(Harshad ...

  4. hdu 4389 囧,打表

    http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 :一个数能被他各个位数之和整除则符合要求,给L,R,问区间里有多少个数符合要求. 囧,居然打表就能过 ...

  5. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  6. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

  7. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  8. hdu 1312 Red and Black 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 第二条深搜,题目并不难,但是做了我好久好久,由于一个细节,让我赌上了一个晚上的时间. 题目大意: ...

  9. HDU 1429 胜利大逃亡(续) (BFS+位压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

最新文章

  1. 使用postMan测试erp系统登录接口
  2. Nat. Med. | 人工智能临床研究新指南
  3. 将ArrayList保存到SharedPreferences
  4. python dig trace 功能实现——通过Querying name server IP来判定是否为dns tunnel
  5. 【数据结构-查找】4.五千字干活长文带你搞懂——B树和B+树
  6. (三) 一起学 Unix 环境高级编程 (APUE) 之 文件和目录
  7. 爆破linux密码 $6$3uwqC9JI$d9iPRmTDAoXs/IbsplxS3iyeErHqw7fUycacXNHyZk1UCSwFEydl515/zXN7OEwHnyUaqYcNG...
  8. error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/r
  9. 程序包清单签名验证失败_数字世界的手写签名
  10. java stringbuffer原理_深入理解String, StringBuffer, StringBuilder的区别(基于JDK1.8)
  11. 贝叶斯定理到贝叶斯滤波器
  12. Java程序员需要了解的几个开源协议介绍
  13. 应用回归分析第五版电子书_应用回归分析课后习题参考答案 全部版 何晓群,刘文卿...
  14. 计算机病毒note01
  15. 如何查询电脑最大可扩展内存
  16. centos7随机生成密码
  17. 组件分享之后端组件——用Go编写的IMAP4rev1库go-imap
  18. oracle stdevp函数,SQL Server和Oracle的常用函数对比
  19. WKWebview使用记录
  20. BIM技术在家装中有5大应用,您知道吗?

热门文章

  1. 专业版网上企业订货平台-移讯云订货系统
  2. 有没有测试鼠标是否丢帧的软件,深澜大叔教你如何准确检测鼠标是否丢帧
  3. 定义c语言字符串的三种方法
  4. python 热图颜色_Python可视化matplotlibseborn14-热图heatmap
  5. mysql temporary table select_MYSQL中的CREATE TEMPORARY TABLE | 学步园
  6. Spring之Bean的自动装配
  7. 一份超详细的Java问题排查工具单
  8. DHCP两种地址池与中继的理解与应用【eNSP实现】
  9. Verilog 与门
  10. 素数求解的C语言方法