hdu 6105 Gameia(多校联赛)

来源:互联网 发布:淘宝旺旺名称怎么修改 编辑:程序博客网 时间:2024/05/29 17:47

Gameia

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


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
T100
1N500
0K500
1Pii
 

Output
For each test case output one line denotes the answer.
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

题意:给出一棵树,Alice 和 Bob 轮流操作, Alice先手, Alice的操作是选一个未染色的点将其染成白色,Bob的操作是选一个未染色的点将其染成黑色,并且和这个点有直连边的点也被强制染成黑色(无论这些直连点之前是否有颜色),Bob还有一个小技能是去掉一条边,最后当所有点都有颜色的时候,如果有白色点则Alice赢,否则Bob赢。

一道博弈题目 本来博弈是我专攻的方向 但是我在比赛的时候 却没能做出来 也感觉非常遗憾 该开始看这道题的时候一看到树 就像立马放弃了 因为我个人对数据结构并不熟悉 以为是一些树的延伸 和博弈没有太大的关系 就没敢继续深入下去 后来比赛结束后问别人才发现这就是一道纯正的数论题 后来想了想 如果可以认真的取理解题意 好好的画画图去推导博弈关系 也许有可能做出来 。

通过画图推演(通过图推到所有过程) 先按照棋盘位置个数奇偶性来判断 如果是奇数个数的话 alice赢 如果是偶数的话 需要先判断棋盘的形状 如果棋盘分支的一个父亲节点有两个儿子以上(即不是链状)则alice必赢  如果每个父节点 都只有一个儿子(即成链状) 那么此时bob的vip权力  看他能切的刀数能不能把链恰好分成两两一对(刀数>=位置/2-1) 如果能则bob赢 否则alice赢

ac代码;

#include <bits/stdc++.h>using namespace std;const int maxn = 1e3;int main(){    int t;    cin >> t;    while(t--)    {        int n, k, father[maxn], size[maxn];//size表示当前节点的子节点个数        bool flag = true;        cin >> n >> k;        for(int i = 2; i <= n; ++ i)            cin >> father[i];        for(int i = 1; i <= n; ++ i)            size[i] = 1;        for(int i = n; i >= 1; -- i)        {            if(size[i] >= 3)                flag = false;            size[father[i]] += size[i] & 1;        }        if(flag && n % 2 == 0 && k >= n / 2 - 1)            cout << "Bob" << endl;        else            cout << "Alice" << endl;    }    return 0;}


原创粉丝点击