描述

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. HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
  2. java获取环境变量路径_通过System获取java环境变量的路径
  3. 用workbench给表重命名_MySQL Workbench的使用方法(图文)
  4. 解决mac升级后,出现的 xcrun: error: invalid active developer path, missing xcrun 错误
  5. spring vaadin_在Spring Boot中使用Vaadin的简介
  6. 如何快速实现 Wordpress 博客域名更换?
  7. “约见”面试官系列之常见面试题之第九十五篇之vue-router的组件组成(建议收藏)
  8. CentOS更改yum源与更新系统
  9. OSS内文件如何设置为无时间限制的下载链接
  10. Error:Could not find common.jar (android.arch.core:common:1.0.0)
  11. MATLAB SMRF点云滤波算法
  12. 【Matlab】mat2cell用法
  13. 全国离线地图矢量地图矢量数据点线面数据
  14. 关于数字雨特效的学习
  15. 参考文献格式字号字体_参考文献标准格式字体
  16. 【日语学习】动词、形容词、名词的敬体形、简体形
  17. Bypass Windows AppLocker
  18. c++::举例_举例说明:网络
  19. 华为笔试题2020(3月11日)
  20. 婚恋交友网站开发搭建源码分享

热门文章

  1. Windows上PHP扩展的实现,部署及应用
  2. securecrt连接GNS3步骤
  3. 知道Google map上面街景怎么来的吗?-相当强大
  4. 'adb' 不是内部或外部命令,也不是可运行的程序或批处理文件
  5. win10 cortana 搜索无效怎么解决
  6. Codeforces Round #547 (Div. 3) D
  7. Eclipse没有server 配置Tomcat
  8. 五大常用经典算法—回溯算法
  9. Java并发编程—线程间协作方式wait()、notify()、notifyAll()和Condition
  10. 1. VIM 系列 - 简单入门,拾起兴趣