HDU 6105 (2017 多校训练赛6 1010)Gameia(博弈)
来源:互联网 发布:淘宝店铺怎么提高流量 编辑:程序博客网 时间:2024/05/23 16:55
2017 Multi-University Training Contest - Team 6 1010
Gameia
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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?
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
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
Output
For each test case output one line denotes the answer.
If Alice can win, output "Alice" , otherwise "Bob".
If Alice can win, output "Alice" , otherwise "Bob".
Sample Input
22 113 11 2
Sample Output
BobAlice
#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <string>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <set>#include <ctime>#include <cmath>using namespace std;const int maxn=2000+5;int father[maxn];int vis[maxn];vector<int>g[maxn];int du[maxn],n;int toposort(){ memset(du,0,sizeof(du)); memset(vis,0,sizeof(vis)); int ans=0; for(int i=1;i<=n;i++) { for(int j=0;j<g[i].size();j++) { du[i]++; } } queue<int>Q; for(int i=1;i<=n;i++) { if(!du[i]) { Q.push(i); } } while(!Q.empty()) { int x=Q.front(); Q.pop(); int t=father[father[x]];// printf("x=%d t=%d\n",x,t); if(father[x]!=-1&&!vis[x]&&!vis[father[x]]) { du[t]--; vis[x]=1; vis[father[x]]=1; ans++; } else { return -1; } if(!du[t]) Q.push(t); } return ans;}int main(){ int T; scanf("%d",&T); while(T--) { for(int i=0;i<maxn;i++) g[i].clear(); memset(father,-1,sizeof(father)); int k; scanf("%d%d",&n,&k); for(int i=2;i<=n;i++) { scanf("%d",&father[i]); g[father[i]].push_back(i); } int ans=toposort();// printf("! %d\n",ans-1); if(ans==-1||ans-1>k) printf("Alice\n"); else printf("Bob\n"); }}
阅读全文
1 0
- HDU 6105 (2017 多校训练赛6 1010)Gameia(博弈)
- HDU-2017 多校训练赛6-1010-Gameia
- hdu -- 6105 -- Gameia(博弈)
- HDU 6105 Gameia (博弈)
- hdu 6105 Gameia (博弈)
- hdu 6105 Gameia(博弈)
- HDU 6105 Gameia 博弈(思维)
- HDU 6105 Gameia(树+博弈)
- HDU 6105 Gameia(博弈+二分匹配)
- HDU 6105 Gameia 博弈
- HDU 6106 (2017 多校训练赛6 1011)Classes
- HDU 6105 Gameia(2017多校第6场1010)
- HDU-2017 多校训练赛9-1010-Two strings
- HDU-2017 多校训练赛10-1010-Schedule
- Gameia(HDU 6105)
- HDU-2017 多校训练赛6-1003-Inversion
- HDU-2017 多校训练赛6-1008-Kirinriki
- HDU-2017 多校训练赛6-1011-Classes
- Linux执行ls,会引起哪些系统调用
- java基础之System类
- 装饰(包装)设计模式学习笔记
- Intellij 加载文件 FileNotFoundException 异常处理
- qduoj 帅气的HYC的珍珠(树状数组)
- HDU 6105 (2017 多校训练赛6 1010)Gameia(博弈)
- 博主介绍
- Qt5基本教程
- obs 核心结构体(四)
- 二叉树面试题(部分)
- C#之入门总结_网络编程_18
- 你需要知道的、有用的 Python 功能和特点
- shell脚本实现分日志级别输出
- const和readonly 小结