Hdu 6105 Gameia【思维+二分匹配】
2017-08-11 18:19
489 查看
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
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
题目大意:
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");
}
}
相关文章推荐
- HDU 6105 Gameia(博弈+二分匹配)
- HDU-6105 Gameia - 2017 Multi-University Training Contest - Team 6(思维之找规律或二分图最大匹配)
- HDU 6105 Gameia(思维博弈)
- HDU 6105 Gameia【思维+博弈】
- HDU 6105 Gameia 博弈(思维)
- hdu 6105-二分匹配
- hdu-2444,hdu-1083 (二分匹配)
- hdu 1068 二分匹配 匈牙利算法
- HDU 2458 最大团个数=顶点数 - 补图最大匹配数 二分匹配
- hdu 3829 Cat VS Dog (二分匹配 求 最大独立集)
- hdu 2444 The Accomodation of Students(判二分+最大匹配)
- HDU2389 Rain on your Parade 二分匹配 Hopcroft-Carp的算法+模版
- HDU 3861--The King’s Problem【scc缩点构图 && 二分匹配求最小路径覆盖】
- HDU-1281-棋盘游戏 [二分匹配][关键匹配]
- HDU 1083 Courses(二分匹配匈牙利算法模板题啊)
- HDU 2819 Swap (最大二分匹配+输出路径)
- hdu 1507 二分匹配
- HDU 3081 Marriage Match Il【并查集 + 二分匹配】
- HDU 6105 Gameia
- 【二分匹配】 HDU 5093 Battle ships 经典二分题