Game-图的基本运用
来源:互联网 发布:怎么导全站仪数据到u盘 编辑:程序博客网 时间:2024/05/22 13:17
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
//题意是alice和bob玩游戏,alice有m1个石子,bob有m2个石子,现在需要把各自的石子全部移动到根节点,alice先移,谁不能移动谁就输了。
//邻接矩阵存储,深搜查找各个节点到根节点的路径,并累加,谁多谁赢。
#include<cstdio>#include<cstring>int parent[30][30],vis[30],n,m1,m2,maxn;void dfs(int k,int step){ if(k==0) { if(step<maxn) { maxn=step; return; } } for(int j=0;j<n;j++) { if(!vis[j]&&parent[k][j]==1) { vis[j]=1; dfs(j,step+1); vis[j]=0; } }}int main(){ int a,b,i,alice,bob; while(scanf("%d%d%d",&n,&m1,&m2)!=EOF) { memset(parent,0,sizeof(parent)); for(i=1;i<n;i++) { scanf("%d%d",&a,&b); parent[a][b]=1; parent[b][a]=1; } alice=bob=0; for(i=1;i<=m1;i++) { scanf("%d",&a); maxn=0xffff; memset(vis,0,sizeof(vis)); vis[a]=1; dfs(a,0); alice+=maxn; } for(i=1;i<=m2;i++) { scanf("%d",&a); maxn=0xffff; memset(vis,0,sizeof(vis)); vis[a]=1; dfs(a,0); bob+=maxn; } if(alice<=bob) printf("Bob\n"); else printf("Alice\n"); } return 0;}
- Game-图的基本运用
- adb的基本运用
- JPA的基本运用
- service的基本运用
- 一些基本的 SQL 运用
- 枚举的基本运用方法
- 树的基本运用一
- 树的基本运用二
- 基本语句的综合运用
- asp.net的基本运用
- sublime text3 的基本运用
- Java线程的基本运用
- 树状数组的基本运用
- myeclipse servlet的基本运用
- 自定义view的基本运用
- 策略模式的基本运用
- 观察者模式的基本运用
- ssh框架的基本运用
- 模式匹配算法汇总
- 《Objective-C高级编程:引用计数和strong ,weak
- 详解tomcat7 的新特性和新增功能
- 【LeetCode】【Python】Sort Colors
- 用Tsung对XMPP进行压力测试,登陆用户只有十几个,无法再添加,何故?
- Game-图的基本运用
- hdu 4341 Gold miner(分组背包)
- Android推送 百度云推送 入门篇
- Ubuntu 14.04下eclipse闪退的解决办法
- Android 插件化
- 下次登陆自动输入账号密码
- nginx源码
- PLSQL创建表序列
- qt 之Uuid