您的位置:首页 > 其它

Game

2014-04-01 21:32 120 查看


Problem Description

Bob always plays game with Alice. Today, they are playing a game on a tree. Alice has m1 stones, Bob has m2 stones. At the beginning of the game, all the stones are placed on the nodes of a tree, except the root. Alice moves first and they take turns moving
the stones. On each turn, the player chooses exactly ONE of his stones, moves this stone from current node to its parent node. During the game, any number of stones can be put on the same node. The player who first moves all of his stones to the root of the
tree is the loser. Assume that Bob and Alice are both clever enough. Given the initial positions of the stones, write a program to find the winner.


Input

Input contains multiple test cases.

The first line of each test case contains three integers(1<n<=10),m1(1<=m1<=3),m2(1<=m2<=3), n is the number of nodes.

Next n-1 lines describe the tree. Each line contains two integers A and B in range[0,n), representing an edge of the tree and A is B's parent. Node 0 is the root.

There are m1 integers and m2 integers on next two lines, representing the initial positions of Alice's and Bob's stones.

There is a blank line after each test case.


Output

output the winner's name on a single line for each test case.


Sample Input

3 1 1
0 1
2 0
1
2

3 2 1
0 1
1 2
2 2
2



Sample Output

Bob
Alice

/*

题意:   有N个节点(标号从 0 到 N-1),Alice有m1个石头,Bob有m2个石头,分别放在各个节点上(1,N-1).

每个节点上可以放无数个石头,Alice先走,Bob后走。

规则:石子只能当前节点上往父节点移,谁先把所有的石头都移到根节点上(0号节点),谁就输了。

解题报告:N个点,N-1条边无回路,形成一颗树。统计Alice和Bob的石子分别位于树的第几层(0号节点为第0

层,石子在第几层就可以走多少步)把他们所有石子的步数分别算出来,比较大小,如果Alice的步

数>Bob的步数,Alice赢,否则Bob赢。

*/

//标程:

#include <iostream>
#include <cstring>
using namespace std;
int map[20][20],node_num;
int visit[20],record[20];
void dfs(int x, int step)
{
for(int i = 0; i < node_num; i ++)
{
if(map[x][i] && !visit[i])
{
visit[i] = 1;
record[i] = step;
dfs(i,step+1);
visit[i] = 0;
}
}
}
int main()
{
//  freopen("a.txt","r",stdin);
int  m1,m2;
while(cin >> node_num >> m1 >> m2)
{
memset(map,0,sizeof(map));
memset(record, 0, sizeof(record));
int i, node_1, node_2;
for(i = 0; i < node_num-1; i ++)
{
cin >> node_1 >> node_2;
map[node_1][node_2] = 1;
map[node_2][node_1] = 1;
}
memset(visit, 0, sizeof(visit));
visit[0] = 1;
dfs(0,1);
int sum_Alice=0, sum_Bob=0, node=0;
for(i= 1; i <= m1; i ++)
{
cin >> node;
sum_Alice += record[node];
}
for(i= 1; i <= m2; i ++)
{
cin >> node;
sum_Bob += record[node];
}
if(sum_Alice > sum_Bob) cout << "Alice" << endl;
else cout << "Bob" << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: