HDU 6105 Gameia 博弈

20 篇文章 0 订阅

题目链接:HDU 6105

Gameia

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


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可以把一个节点和周围相连的所有节点都涂成黑的,包括白的,之后Bob有k次机会去掉一条边,但是不能去掉点,其实就是把树拆开,如果涂完后有节点是白的则Alice赢,否则Bob赢。
题目分析:
比赛的时候随便涂鸦居然涂出来思路了,,,发现在不减边的情况下2个点1条边的情况下Bob赢,其他情况均会输掉。所以如果剪边也只能剪成一堆单个边。如果能剪并且数量足够则Bob,否则Alice。对于如何判断之前我没有往二分图想,然后BFS没过,之后改成DFS的二分图匹配过了
//
//  main.cpp
//  Gameia
//
//  Created by teddywang on 2017/8/10.
//  Copyright © 2017年 teddywang. All rights reserved.
//

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int fa[1111];
bool vis[555][555];
bool d[555];
int cp[555];
int n,k;
int pipei(int a)
{
    for(int i=1;i<=n;i++)
    {
        if(!d[i]&&vis[a][i])
        {
            d[i]=1;
            if(!cp[i]||pipei(cp[i]))
            {
                cp[i]=a;
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&k);
        memset(d,0,sizeof(d));
        memset(cp,0,sizeof(cp));
        memset(vis,0,sizeof(vis));
        for(int i=2;i<=n;i++)
        {
            scanf("%d",&fa[i]);
            vis[fa[i]][i]=vis[i][fa[i]]=1;
        }
        if(n&1)
        {
            printf("Alice\n");
            continue;
        }
        if(k<(n-1)/2)
        {
            printf("Alice\n");
            continue;
        }
        int cnt=0;
        int flag=1;
        for(int i=1;i<=n;i++)
        {
            memset(d,0,sizeof(d));
            if(pipei(i)) cnt++;
            else break;
        }
        if(cnt!=n) flag=0;
        if(flag==0) printf("Alice\n");
        else printf("Bob\n");
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值