2017 Multi-University Training Contest - Team 6 Gameia(博弈论+dfs)

25 篇文章 4 订阅
11 篇文章 0 订阅

Gameia

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


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
 

Source
 

Recommend
liuyiding
 

题目大意:两个人在对一棵树进行博弈,Bob能够在每次操作前一次或者多次将边切断,然后Alice先手点一个未染色的点,然后这个点和所连接的点全部为白色,Bob后手点黑色,两个人都必须点未染色的点,已经被染色的点可以重复被点,现在给Bob m次操作,问获胜的是谁
解题思路:值得注意的事,若是在允许操作的次数之内,可以将所有的点都两两分组,若是可以则Bob可以,否则Alice获胜,至于这个需要用dfs
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

vector<int> tu[505];
int T,n,m,flag;
int vis[505];
void dfs(int x,int y)
{
	int i,k;
	for(i=0;i<tu[x].size();i++)
	{
		k=tu[x][i];
		if(k==y) continue;
		dfs(k,x);
		if(vis[k]==0&&vis[x]==0)
		{
			vis[k]=1;
			vis[x]=1;
		}
		else
		{
			m--;
		}
	}
}
int main()
{
	int k,i,x;

	cin>>T;
	while(T--)
	{
		memset(tu,0,sizeof(tu));
		cin>>n>>m;
		for(i=2;i<=n;i++)
		{
			cin>>x;
			tu[x].push_back(i);
			tu[i].push_back(x);
		}
		flag=0;
		memset(vis,0,sizeof(vis));
		dfs(1,0);
		for(i=1;i<=n;i++)
		{
			if(vis[i]==0)
			{
				flag=1;
				break;
			}
		}
		if(m<0)
			flag=1;
		if(flag)
		{
			cout<<"Alice"<<endl;
		}
		else
		{
			cout<<"Bob"<<endl;
		}
	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值