HDU 6105 Gameia 博弈

題目鏈接: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");
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章