HDU 6105-Gameia

本文介绍了一个有趣的博弈游戏“Gameia?Gameia!”,探讨了Alice和Bob如何通过轮流染色节点来争夺胜利的策略。特别关注Bob如何利用有限次数的特权改变游戏树结构以获得优势。

Gameia

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


题目链接: 点击打开链接

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玩一个游戏,一开始有一颗有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的点不能大于1.






#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define max_n 510
using namespace std;
int vis[max_n];

int main()
{
    int t, n, k, p;
    scanf("%d", &t);
    while(t--)
    {
        bool flag = true;
        vector<int> v[max_n];
        memset(vis, 0, sizeof(vis));
        scanf("%d %d", &n, &k);
        for(int i = 2; i <= n; i++)
        {
            scanf("%d", &p);
            vis[p] = 1;//将出现的节点标记一下
            v[p].push_back(i);//将以p为父亲的节点都添加在v[p]后面
        }
        for(int i = 1; i <= n; i++)
        {
            int sum1 = 0;
            for(int j = 0; j < v[i].size(); j++)
            {
                if(!vis[ v[i][j] ])  //判断以i为父亲节点连接的有几个入度为1的点
                    sum1++;
            }
            if(sum1 > 1)
            {
                flag = false;
                break;
            }
        }
        if(k < n / 2 - 1 || n % 2 == 1 || !flag) printf("Alice\n");
        else printf("Bob\n");
    }
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值