描述

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. Office Diary(工作日记本)

    Office Diary 是一款免费.绿色小巧的写日记和收集文档资料的软件,界面效仿Office Word ,支持Word中常用的文字编辑排版功能,可以作为Microsoft Office产品系列的强 ...

  2. mac下redis和zookeeper启动及测试命令

    mac下启动命令:    sudo su - root cd /usr/local/bin/    ./redis-server ../etc/redis.conf cd /software/zook ...

  3. 网页的js源文件被加密解决方案

    Firefox和Chrome都具有这个功能,而且位置几乎一致

  4. luoguP4396 [AHOI2013]作业

    https://www.luogu.org/problemnew/show/P4396 简单的莫队+树状数组,但博主被卡常了,不保证代码在任何时候都能AC #include <bits/stdc ...

  5. spark执行例子eclipse maven打包jar

    首先在eclipse Java EE中新建一个Maven project具体选项如下 点击Finish创建成功,接下来把默认的jdk1.5改成jdk1.8 然后编辑pom.xml加入spark-cor ...

  6. FJWC2019 子图 (三元环计数、四元环计数)

    给定 n 个点和 m 条边的一张图和一个值 k ,求图中边数为 k 的联通子图个数 mod 1e9+7. \(n \le 10^5, m \le 2 \times 10^5, 1 \le k \le ...

  7. 关于hive Metadata 使用 MsSQL

    下面的页面里说明, http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.0.6.0-Win/bk_installing_hdp_for_window ...

  8. 谈谈easyui datagrid 的数据加载

    文章目录 1url方式加载数据 1.1调用方式 1.2相关方法 1.3二次加载问题 2加载本地数据方式 2.1调用方式 2.2如何分页 2.3加载中效果 2.4如何不统计总数 这篇文章只谈jQuery ...

  9. 洛谷 P1217 [USACO1.5]回文质数 Prime Palindrome

    嗯... 这道题对于蒟蒻的我来说实在是TQL... 先看一下题:(题目链接:https://www.luogu.org/problemnew/show/P1217) 然后说一下我的做题过程吧: 一看到 ...

  10. screen虚拟终端

    screen命令相当于后台执行(虚拟终端) 用法:在一些要执行很久的操作,比如我有个文件有10个G,要传输一天左右,你如果是直接传输,万一你的连接断了.是不是意味着你的操作白费的呢,这时我们可以打开一 ...