hdu 6105 Gameia【图+博弈详解】

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
T≤100
1≤N≤500
0≤K≤500
1≤Pi≤i

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

Source
2017 Multi-University Training Contest - Team 6
题意:
给定一个树,A可以选一个未染色结点染成白色 B有k次机会可以在任何时候切断一条连边,B可以选一个未染色结点染成黑色,同时和这个结点连接的点也会变成黑色(无论是白色还是未染色),本题是个无向图。最后还有白色的结点那么A赢否则B赢。
思路:
图 + 博弈。找规律发现,A最优时B要想最优,一次只能染一个黑色+把白色变成黑色这两个点(最后一步除外),那么只要n是奇数,最后A一定赢。n为偶数时,按照奇数的分析,只要让B染奇数点(加上污染白色的点)这是最优的情况,B也不想染奇数点,就把染过的点偶数点给剪了(防止被染),A就赢,否则B赢。只需要把这棵树切成两两分堆,那么B就赢了,只有n为偶数并且能两两分(k >= n / 2 - 1)B才能赢。
当任何一个点周围不存在两个或以上 度为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);
        }
        for(int i = 1; i <= n; i++) {
            int sum1 = 0;
            for(int j = 0; j < v[i].size(); j++) {
                if(!vis[ v[i][j] ])  //判断周围连接的有几个入度为1的点 
                    sum1++;
            }
            if(sum1 > 1) {
                flag = false;
                break;
            }
        }
        if(k < n / 2 - 1 || n % 2 == 1 || !flag) printf("Alice\n");
        else printf("Bob\n");
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值