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 movingthe 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; }
相关文章推荐
- Eric's Picross Game 一个用JS和CSS(当然在HTML里)写的WEB小游戏.
- POJ 1740:A New Stone Game
- [POI2013]Tower Defense Game
- Building a WPF Sudoku Game: Part 4 - Building a Least Privilege Plug-in System and Even More Custom Controls
- TOJ 3848 Game 矩阵快速幂
- 【ZOJ3316】Game(带花树)
- Object-Oriented Game Design (面向对象的游戏设计)
- 1343 - The Rotation Game
- [ZOJ3329] One Person Game
- Multithreaded Game Programming and Hyper-Threading Technology
- POJ 2996:Help Me with the Game
- jump-game i&&ii 能否跳出区间 贪心
- weekly review 200804: Drunk-Game-Video
- HDOJ 题目1760 A New Tetris Game(DFS,博弈)
- 遭遇RootKit.Win32.GameHack.GEN,Trojan.PSW.Win32.GameOL.GEN,RootKit.Win32.Mnless等2
- 【Unity游戏开发之四】GameObject.Find()、Transform.Find查找隐藏对象
- 武士之旅小游戏(Chess Board game: Tour of knight)
- [IOS]今天开始学UI---UIButton with NumberMatch Game
- 一个开源五子棋game
- hdoj-1034-Candy Sharing Game