描述

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*]; 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();
dist[]=;
while(!Q.empty()){
int t=Q.front();
Q.pop();
for(int i=head[t]; i!=-; i=edge[i].next){
int c=edge[i].to;
if(!visited[c]){
visited[c]=;
dist[c]=dist[t]+;
Q.push(c);
}
}
}
}
int main(int argc, char *argv[])
{
int u,v,p1,p2;
while(scanf("%d %d %d",&n,&m1,&m2)!=EOF){
cnt=;
memset(head,-,sizeof(head));
memset(visited,,sizeof(visited));
memset(dist,,sizeof(dist));
for(int i=; i<n; i++){
scanf("%d %d",&u,&v);
addedge(u,v);
addedge(v,u);
}
int sum1=,sum2=;
dist[]=;
bfs();
for(int i=; i<m1;i++){
scanf("%d",&p1);
sum1+=dist[p1];
}
for(int i=; i<m2; i++){
scanf("%d",&p2);
sum2+=dist[p2];
}
if(sum1>sum2){
puts("Alice");
}else{
puts("Bob");
}
}
return ;
}

TOJ 4393 Game的更多相关文章

  1. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  2. 【HDOJ】4393 Throw nails

    水题,优先级队列. /* 4393 */ #include <iostream> #include <sstream> #include <string> #inc ...

  3. TOJ 1702.A Knight's Journey

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

  4. TOJ 1139.Compromise

    2015-06-03 问题简述: 大概就是输入两段文本(用小写英文字母表示),分别用#表示一段话的结束输入,输出这两个文本的最长公共子序列. 简单的LCS问题,但是输入的是一段话了,而且公共部分比较是 ...

  5. 优先队列运用 TOJ 4123 Job Scheduling

    链接:http://acm.tju.edu.cn/toj/showp4123.html 4123.   Job Scheduling Time Limit: 1.0 Seconds   Memory ...

  6. 最小生成树 TOJ 4117 Happy tree friends

    链接http://acm.tju.edu.cn/toj/showp4117.html 4117.   Happy tree friends Time Limit: 1.0 Seconds   Memo ...

  7. TOJ 4120 Zombies VS Plants

    链接:http://acm.tju.edu.cn/toj/showp4120.html 4120.   Zombies VS Plants Time Limit: 1.0 Seconds   Memo ...

  8. TOJ 3365 ZOJ 3232 It's not Floyd Algorithm / 强连通分量

    It's not Floyd Algorithm 时间限制(普通/Java):1000MS/3000MS     运行内存限制:65536KByte   描述 When a directed grap ...

  9. TOJ 4523 Transportation

    Description Given N stations, you want to carry goods from station 1 to station N. Among these stati ...

随机推荐

  1. Bitmap压缩到指定尺寸大小,获取圆角、圆形图片

    /** * 使用Matrix将Bitmap压缩到指定大小 * @param bitmap * @param w * @param h * @return */ public static Bitmap ...

  2. Log--日志变大原因总结

    1. 有产生大日志操作,如重建整理索引,大量数据修改等2. 长期未提交事务,为保证为提交事务可以回滚,从最早为提交事务开始之后的所有事务,都是活动事务,不能被截断或覆盖3. 日志没有定期备份4. 镜像 ...

  3. .Net高级面试宝典

    1.in/exists/join 执行效率? 答:用法 select * from HK_UsersBasic where  Users_ID in (select AccEmail from dbo ...

  4. hive的安装与配置 mysql安装 启动

    三种模式 内嵌模式:元数据保持在内嵌的derby模式,只允许一个会话连接 本地独立模式:在本地安装Mysql,吧元数据放到mySql内 远程模式:元数据放置在远程的Mysql数据库 1.下载Hive安 ...

  5. 主流C语言编译器介绍

  6. Kylin -- Dup key found 问题

    kylin 构建 cube 时,抛出了如下的错误: org.apache.kylin.engine.mr.exception.HadoopShellException: java.lang.Runti ...

  7. oracle转义用单引号

    参考:https://blog.csdn.net/learning_oracle_lh/article/details/46639507

  8. 深度学习之 TensorFlow(三):TensorFlow 源代码解析

    分析一下 TensorFlow 的文件结构.这里的源代码版本是 TensorFlow1.7.0 . 目录结构如下: 其中的核心目录是 tensorflow 目录,最重要的源代码保存在这里,目录结构如下 ...

  9. GN算法---《Community structure in social and biological networks》这篇论文讲了什么?

    用中文记下这篇论文的大致意思,以防止忘了.好记性不如烂笔头! 摘要:最近的一些研究在研究社交网络或WWW.研究者都集中于研究网络的“小世界性”,“幂率分布特性”,“网络传递性”(聚类性吧).本文提出网 ...

  10. Trie树【洛谷P3879】 [TJOI2010]阅读理解

    P3879 [TJOI2010]阅读理解 题目描述 英语老师留了N篇阅读理解作业,但是每篇英文短文都有很多生词需要查字典,为了节约时间,现在要做个统计,算一算某些生词都在哪几篇短文中出现过. 输入输出 ...