描述

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 turns moving the stones.On each turn,the player chooses exactly one of his stone,moves this stone from current node to his parent node.During the game,any number of stone 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.Assurme that Bob and Alice are both clever enough.Given the initial position of the stones,write a program to find the winner.

输入

Input contains multiple test case.
The first line of each test case cotains three integers n(1<n<=10),m1(1<=m1<=3) and m2(1<=m2<=3) ,n is the number of node.
Next n-1 line 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 root.
There are m1 integers and m2 integers on the next two lines,representing the initial position of Alice's and Bob's stones.

输出

Output the winner of the game.

样例输入

3 1 1
0 1
0 2
1
2
3 2 1
0 1
1 2
2 2
2

样例输出

Bob
Alice

看了半天没看懂题目是什么意思,后来看了一个人的一篇博客才明白是大概是什么的意思。

应该是先把所有的stones移到根节点的人算输,这样子的话只要是把所有的stones所在层数相加和最小的人就输了。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <queue>
#define MAXN 20
using namespace std;int n,m1,m2,cnt;
int dist[MAXN];
int visited[MAXN];
int head[MAXN];struct Edge{int to,next;
}edge[MAXN*2];void addedge(int u, int v){edge[cnt].to=v;edge[cnt].next=head[u];head[u]=cnt++;
}void bfs(){queue<int> Q;Q.push(0);dist[0]=0;while(!Q.empty()){int t=Q.front();Q.pop();for(int i=head[t]; i!=-1; i=edge[i].next){int c=edge[i].to;if(!visited[c]){visited[c]=1;dist[c]=dist[t]+1;Q.push(c);}} }
}
int main(int argc, char *argv[])
{int u,v,p1,p2;while(scanf("%d %d %d",&n,&m1,&m2)!=EOF){cnt=0;memset(head,-1,sizeof(head));memset(visited,0,sizeof(visited));memset(dist,0,sizeof(dist));for(int i=1; i<n; i++){scanf("%d %d",&u,&v);    addedge(u,v);addedge(v,u);}int sum1=0,sum2=0;dist[0]=0;bfs();for(int i=0; i<m1;i++){scanf("%d",&p1);sum1+=dist[p1];}for(int i=0; i<m2; i++){scanf("%d",&p2);sum2+=dist[p2];}if(sum1>sum2){puts("Alice");}else{puts("Bob");}}return 0;
}

转载于:https://www.cnblogs.com/chenjianxiang/p/3540892.html

TOJ 4393 Game相关推荐

  1. TOJ 1702.A Knight's Journey

    2015-06-05 问题简述: 有一个 p*q 的棋盘,一个骑士(就是中国象棋里的马)想要走完所有的格子,棋盘横向是 A...Z(其中A开始 p 个),纵向是 1...q. 原题链接:http:// ...

  2. 数集合有多少个TOJ(2469)

    题目链接:http://acm.tju.edu.cn/toj/showp2469.html 感觉这个题目有点问题,算了不管他了,反正A了. 这里要注意的是求这个集合有多少种,那么就是要剔除重复数后,再 ...

  3. toj 4604 搞笑版费马大定理

    toj 4604 搞笑版费马大定理 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 122 测试通过:67 描述 费马大定理:当n>2时,不定方 ...

  4. toj 4601 好老师

    toj 4601 好老师 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 73 测试通过:37 描述 我想当一个好老师,所以我决定记住所有学生的名字. ...

  5. toj 4597 字符识别?

    toj 4597 字符识别? 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 122 测试通过:95 PS:最好是看原题,这里图案对齐不是那么好. 4 ...

  6. toj 4596 一行盒子

    toj 4596 一行盒子 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 116 测试通过:11 描述 你有一行盒子,从左到右依次编号为1, 2, ...

  7. toj 4319 盒子游戏

    toj 4319 盒子游戏 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 137 测试通过:76 描述 有两个相同的盒子,其中一个装了 n 个球,另 ...

  8. toj 4317 多连块拼图

    toj 4317 多连块拼图 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 40 测试通过:21 描述 多连块是指由多个等大正方形边与边连接而成的平 ...

  9. toj 4316 报数游戏

    toj 4316 报数游戏 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 总提交: 68 测试通过:35 描述 n 个人站成一行玩一个报数游戏.所有人从左到右 ...

最新文章

  1. Mesos:一个开源的分布式弹性资源管理系统
  2. 机器学习_的应用网站记录01_可以上色的网站
  3. 稀疏矩阵的转置c语言程序,程序有问题求大神,稀疏矩阵转置
  4. ScanTailor-ScanTailor 强大的多方位的满足处理扫描图片的需求
  5. 前端学习(2930):内嵌改变样式
  6. IDEA的使用注释编程时,出现报错解决方案
  7. 秋招注意事项和面试通关攻略
  8. [深度学习-原理]浅谈Attention Model
  9. 小明利用计算机软件绘制函数,辽宁省大连市2014年高二学业水平模拟考试 信息技术试题(三)...
  10. 常用编程语言开发工具
  11. Flask框架从入门到精通之消息闪现和日志记录(二十一)
  12. 一个正经的电商运营每天应该看哪些数据?
  13. 分区 MBR文件系统
  14. “法外狂徒”为什么那么多?用程序来告诉你!
  15. Enolsoft PDF Converter with OCR mac(带有OCR的PDF转换器)
  16. Autovue显示dwg等图纸乱码问题解决
  17. 计算机如何开启多个用户,电脑上如何打开多个微信账号?
  18. 在html使用wow,让你的网页有点动画效果
  19. Singing Contest
  20. 纯国产的大佬周志华,如何扛起了智能学界的一面大旗

热门文章

  1. JAVA使用JDBC连接MySQL数据库
  2. Exchange Server2010系列之七:多邮箱搜索找出神秘邮件的幕后黑手
  3. Linux基金会:Linux已经战胜微软
  4. 写段QTP脚本与大家一起分享
  5. 修改MONGODB 最大连接数
  6. 几种查看linux版本信息的方法
  7. android:scaleType的各个属性解释
  8. List类系列(一):list中各元素出现的次数
  9. Android中如何使控件保持固定宽高比
  10. AppBoxFuture(四). 随需而变-Online Schema Change