HDU6105-Gameia
来源:互联网 发布:网络扫描仪工具 编辑:程序博客网 时间:2024/05/16 05:40
Gameia
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1370 Accepted Submission(s): 596
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
Source
2017 Multi-University Training Contest - Team 6
Recommend
liuyiding
题意:Alice和Bob玩一个游戏,开始有一颗没有颜色的树,Bob和Alice分别对树进行染色,Alice每次将一个没有颜色的点涂成白色,Bob每次将一个没有颜色的点涂成黑色,并且可以将与涂上黑色的点直接相邻的点变为黑色。Alice为先手,假如最后树上存在白色点,Alice赢,否则Bob赢。Bob可以在任意时候,删除任意一条边。
解题思路:当树为奇数点数时,Alice必赢,偶数的时候,假如Bob能将树划分为所有都是只有两个点相连的话Bob赢
#include <iostream>#include <cstdio>#include <cstring>#include <map>#include <set>#include <string>#include <cmath>#include <algorithm>#include <vector>#include <bitset>#include <stack>#include <queue>#include <unordered_map>#include <functional>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int fa[505],vis[505],c[505],n,k;int s[505],nt[1005],e[1005],flag;void dfs(int k,int f){ for(int i=s[k];~i;i=nt[i]) { if(e[i]==f) continue; dfs(e[i],k); vis[e[i]]--; if(!flag) return ; } if(vis[k]==1&&!c[k]&&!c[f]) c[k]=c[f]=1; else if(vis[k]==1&&!c[k]&&c[f]) {flag=0;return ;}}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); int cnt=0; memset(s,-1,sizeof s); memset(vis,0,sizeof vis); memset(c,0,sizeof c); for(int i=2;i<=n;i++) { scanf("%d",&fa[i]); nt[cnt]=s[i],s[i]=cnt,e[cnt++]=fa[i]; nt[cnt]=s[fa[i]],s[fa[i]]=cnt,e[cnt++]=i; vis[i]++,vis[fa[i]]++; } if(n%2) {printf("Alice\n");continue;} flag=1; dfs(1,0); if(flag&&k>=(n-1)/2) printf("Bob\n"); else printf("Alice\n"); } return 0;}
阅读全文
0 0
- [hdu6105]Gameia
- HDU6105-Gameia
- hdu6105 Gameia 思维
- Hdu6105 Gameia(2017多校第6场)
- (HDU6105)Gameia(博弈+树的切割)
- hdu6105-多校6&&博弈&图&思维-Gameia
- 2017杭电多校第六场 1010 Gameia(博弈)HDU6105
- HDU6105 [2017duoxiaolianhe6] Gameia 博弈你个香蕉船
- hdu6105 Gameia 2017多校第六场1010 树+博弈
- hdu6105
- hdu6105
- Gameia HDU
- HDU-Gameia
- HDU6105-二分匹配
- hdu6105(博弈)
- hdu6105(想法题)
- hdu6105(想法题)
- HDU_6105 Gameia 【博弈】
- 测试mybatis是出现异常
- Visualizing and Understanding Convolutional Networks阅读笔记
- 算法训练 简单加法(基本型)
- hdu 2157 How many ways??【矩阵快速幂路径问题】
- Thrift 源码分析(一)基本概念
- HDU6105-Gameia
- 树的双亲表示法
- HDU-2017 多校训练赛6-1010-Gameia
- 8.15 Test Problem Solution.
- 外观模式
- 2018网易校招编程题(2) 等差数列
- 【物联网云端对接-2】通过MQTT协议与阿里云物联网套件进行云端通信
- 数据结构编程笔记十二:第五章 数组和广义表 数组顺序存储的实现
- hpuoj【1194】【快速幂】