HDU 6105 Gameia(思维博弈)

Gameia

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1003    Accepted Submission(s): 426


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
  
  
2 2 1 1 3 1 1 2
 

Sample Output
  
  
Bob Alice
 
题意:Alice和Bob玩一个游戏,游戏规则如下
1.有一颗大小为n树可供染色
2.Alice可以对树的未被染色的节点染白色,Bob可以对未被染色的节点染黑色,并且与这一节点相连的节点(不管是白色还是未染色)都会被染成黑色
3.Bob有k次机会可以从树上去掉一条边
4.Alice先手
思路:对于Bob的手段我们分析一下发现因为两个人都足够聪明而且Alice先手,所有可以直接预测所有局势,那么Bob的手段在比赛前动手和比赛时动手效果都一样的,那么我们干脆在比赛前就将树给分解了,那么若分解的点中有一个孤立点,对于先手的Alice来说是必胜的,而若能将树分解成一对一对的连通点,那么Bob可以必胜
我们分析一下一颗树,若树有n个节点,且节点数为奇数个,Bob的手段次数足够多能将树都分解了,那么必有一个孤立点,那么对于先手的Alice必胜,那么若Bob的手段不够多,他只能分解一部分,那么剩下的点还是奇数个,这奇数个点Alice可以涂色中间父节点,Bob被迫只能涂子节点,那么最后肯定是Alice涂最后一点,游戏结束,Alice胜,故树的节点数为奇数时Alice胜
当节点数为偶数时,Bob若能将树分成一对一对连通点Bob能获胜,其他情况时无法获胜,树能否分成一对一对连通点时只要看,一个父节点直接连接的子节点数是否是一个,当为一个时子节点恰可贺父节点分割成一对连通点,若有2个即两个以上的子节点时,子节点之间相互孤立,分割后将成为孤立点,所以Bob会输,故当节点数为偶数时判断父节点的子节点数是不是都小于等于以即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1e3;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,k,f[maxn],s[maxn];
        scanf("%d%d",&n,&k);
        for(int i=2;i<=n;i++)
            scanf("%d",&f[i]);
        for(int i=1;i<=n;i++)
            s[i]=1;
        int flag=1;
        for(int i=n;i>=1;i--)
        {
            if(s[i]>=3)
                flag=0;
            s[f[i]]+=s[i]%2;
        }
        if(flag==1&&n%2==0&&k>=n/2-1)
            printf("Bob\n");
        else
            printf("Alice\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值