2017 Multi-University Training Contest - Team 6:1010&hdu6105、Gameia

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32360995/article/details/77075460

题目:

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
题意:有一棵n个节点的未刷漆的树,Alice将节点刷成白色,而Bob刷成黑色且与这个节点直接相连的节点会变成黑色。Bob是尊贵的VIP,拥有断开两个节点相连的能力(去掉一条边),可以使用k次。如果最后有白色节点,Alice获胜,否则Bob获胜。输出获胜者的名字

思路:自己不会做,总得看别人的题解,郁闷~如果节点数为奇数个的话,Alice获胜;节点数为偶数的话,如果能分成两个节点两个节点一组且次数(只需要分(n/2-1)次,因为最后会剩下两个)不超过K的话Bob获胜;其他情况Alice获胜~自己举几个例子还是挺容易理解的鄙视嗯,我就会马后炮~

题目数据太水了,有人在评论举了组数据,我发现过不了,用递归不能判断能不能分成两两一组的情况,只能推倒重来了。并不是子节点数大于1就是Alice获胜。比如:3 8 10 1 2 3 4 2 6 7   10 1000 1 2 3 4 2 6 7 8 5   10 1000 1 1 1 2 5 3 7 4 9。个人觉得正确做法应该是从叶子结点开始往上删除节点,两个节点删除一次

CODE:

#include<bits/stdc++.h>
using namespace std;
int num[505],vis[505],pre[505];   //num:记录孩子节点数;vis:标记节点有没有被删除;pre:记录父节点
int main(){
        int t,n,k,x,i,j,flag;
        scanf("%d",&t);
        while(t--){
                scanf("%d%d",&n,&k);
                memset(num,0,sizeof(num));
                pre[1]=1;
                for(i=2;i<=n;i++){
                        scanf("%d",&x);
                        num[x]++;
                        pre[i]=x;
                }
                if(n%2) puts("Alice");
                else{
                        memset(vis,0,sizeof(vis));
                        flag=0;
                        for(i=0;i<n;i++){
                                for(j=2;j<=n;j++){
                                        if(!num[j]&&!vis[j]){
                                                if(vis[pre[j]]){
                                                        flag=1;
                                                        break;
                                                }
                                                //满足条件就删除这两个节点
                                               vis[j]=vis[pre[j]]=1;
                                                num[pre[pre[j]]]--;
                                        }
                                }
                                if(flag) break;
                        }
                        if(n/2-1>k) flag=1;
                        if(flag) puts("Alice");
                        else puts("Bob");
                }
        }
        return 0;
}

阅读更多

没有更多推荐了,返回首页