Hdu 6105 Gameia【思维+二分匹配】

Gameia

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


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

题目大意:


A和B两个人玩游戏,A先手,B后手,A每一次操作可以选择任意一个没有染色的点,将其染色为白色。B每一次操作可以选择任意一个没有染色的点,将其染成黑色,并且这个点直接相连的所有点都变成黑色(即使是白色也会被染成黑色)。因为B玩家是VIP玩家,所以他有K次机会拆边,当没有人可以进行操作的时候,游戏结束,当还存在白色点的时候,A赢,否则B赢。


思路:

因为B想赢涉及到拆边之类的复杂操作,所以我们不妨先考虑Bob赢都有哪些情况。

我们通过枚举和YY,不难想到,只有当我们n为偶数,并且能够将图拆成两两配对的情况才能获胜。这样可以有一个对称博弈的思路,就是A先手无论涂哪一个点的颜色,我们Bob都可以后手将这个白色覆盖掉。


那么问题就变成了一个二分图匹配,只有当n%2==0&&K>=(n-1-n/2)的时候,我们的图还是一个能够凑成完美匹配的一个图,才能使得Bob获胜。将边拆剩n/2条,然后两两配对出来。


否则就是Alice赢。


Ac代码:

#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
vector<int>mp[505];
int match[505];
int vis[505];
int f[505];
int find(int u)
{
    for(int i=0;i<mp[u].size();i++)
    {
        int v=mp[u][i];
        if(vis[v]==0)
        {
            vis[v]=1;
            if(match[v]==-1||find(match[v]))
            {
                match[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,k;
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)mp[i].clear();
        for(int i=2;i<=n;i++)
        {
            scanf("%d",&f[i]);
            mp[f[i]].push_back(i);
            mp[i].push_back(f[i]);
        }
        if(n%2==0&&(n-1-n/2)<=k)
        {
            int tot=0;
            memset(match,-1,sizeof(match));
            for(int i=1;i<=n;i++)
            {
                memset(vis,0,sizeof(vis));
                if(find(i))tot++;
            }
            if(tot==n)printf("Bob\n");
            else printf("Alice\n");
        }
        else printf("Alice\n");
    }
}














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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值