hdu 6105 Gameia (博弈)

http://acm.hdu.edu.cn/showproblem.php?pid=6105
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

题目大意:Alice和Bob玩一个游戏,一开始有一颗有n个节点并且没有颜色的树,Bob和Alice分别对树上的节点进行染色,Alice每次将一个没有颜色的点涂成白色,Bob每次将一个没有颜色的点涂成黑色,并且可以将与涂上黑色的这个点直接相邻的点变为黑色,假如最后树被涂满之后还存在白色点,Alice赢,否则Bob赢。Bob还有一个特权,可以在任意时候,删除任意一条边,这样的特权可以使用k次。

解题思路:最核心的一句话就是如果Bob能把这棵树分成若干两个一组的点对,那么Bob取得胜利,否则Alice获胜。
1.两两一组肯定需要树的节点个数为偶数。
2.因为Alice先走,所以Alice如果每次选择的都是树的父节点不管Bob走哪他都可以赢。Bob为了取得胜利,需要将Alice走的每一步之后把她走的颜色给涂成黑色,也就是分割成两两相连的组。这时候,Bob的特权k次数就肯定需要满足:k>= n / 2 – 1
3.每个节点的叶子节点个数不能大于1。

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int T;scanf("%d",&T);
    while(T--){
        int n,k,a,vis[505],flag = 1;
        vector<int> t[505];
        scanf("%d %d",&n,&k);
        memset(vis,0,sizeof(vis));
        for(int i=1;i<n;i++)
        {
            scanf("%d",&a);
            vis[a] = 1;
            t[a].push_back(i+1);///建树
        }
        for(int i=1;i<=n;i++)
        {
            int sum = 0;
            for(int j=0;j<t[i].size();j++)
                if(vis[t[i][j]]==0)//记录每个节点的叶子节点个数
                    sum++;
            if(sum>1)
            {
                flag = 0;
                break;
            }

        }
        if((n%2==0)&&(k>=n/2 -1)&&(flag))///如果同时满足这三种情况就是Bob赢,否则就是Alice赢
            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、付费专栏及课程。

余额充值