You are my brother NBUT - 1218
问题描述
Little A gets to know a new friend, Little B, recently. One day, they realize that they are family 500 years ago. Now, Little A wants to know whether Little B is his elder, younger or brother.
输入
There are multiple test cases.
For each test case, the first line has a single integer, n (n<=1000). The next n lines have two integers a and b (1<=a,b<=2000) each, indicating b is the father of a. One person has exactly one father, of course. Little A is numbered 1 and Little B is numbered 2.
Proceed to the end of file.
输出
For each test case, if Little B is Little A’s younger, print “You are my younger”. Otherwise, if Little B is Little A’s elder, print “You are my elder”. Otherwise, print “You are my brother”. The output for each test case occupied exactly one line.
样例输入
5
1 3
2 4
3 5
4 6
5 6
6
1 3
2 4
3 5
4 6
5 7
6 7
样例输出
You are my elder
You are my brother
提示
无
来源
辽宁省赛2010
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
typedef long long ll;
const int maxn=11000;
const int INF=0x3f3f3f3f;
int a,b,n;
int fa[maxn];
int main()
{
while(cin>>n)
{
int x1,x2,cot1,cot2;
for(int i=0; i<maxn; i++)
fa[i]=i;
while(n--)
{
scanf("%d %d",&a,&b);
fa[a]=b;
}
x1=1;
cot1=0;
while(fa[x1]!=x1)
{
x1=fa[x1];
cot1++;
}
x2=2;
cot2=0;
while(fa[x2]!=x2)
{
x2=fa[x2];
cot2++;
}
if(cot1>cot2)
printf("You are my elder\n");
else if(cot1<cot2)
printf("You are my younger\n");
else
printf("You are my brother\n");
}
return 0;
}
You are my brother NBUT - 1218的更多相关文章
- NBUT 1218 You are my brother 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ...
- NBUT 1218 You are my brother
$dfs$. 记录一下每一个节点的深度就可以了. #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- NBUT 1457 莫队算法 离散化
Sona Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 145 ...
- fzoj1314 You are my brother
题目描述 Little A gets to know a new friend, Little B, recently. One day, they realize that they are fam ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1105 多连块拼图 - 水题 - 模拟
NBUT 1105 多连块拼图 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- 远程监控显示brother数控机床数据
最近几个月公司太忙了,到现在已经连续出差两个多月了. 这个项目这要做mes系统,涉及到产品在机床的加工过程监控,然后led看板显示产品进度. 这里的主角是日本的brother数控机床,服务器按照一定频 ...
- 图论 --- spfa + 链式向前星 (模板题) dlut 1218 : 奇奇与变形金刚
1218: 奇奇与变形金刚 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 130 Solved: 37[Submit][Status][Web Boa ...
- 【CodeVS 1218】【NOIP 2012】疫情控制
http://codevs.cn/problem/1218/ 比较显然的倍增,但是对于跨过根需要很多讨论,总体思路是贪心. 写了一上午,不想再说什么了 #include<cstdio> # ...
随机推荐
- 【点分治练习题·不虚就是要AK】点分治
不虚就是要AK(czyak.c/.cpp/.pas) 2s 128M by zhb czy很火.因为又有人说他虚了.为了证明他不虚,他决定要在这次比赛AK. 现在他正在和别人玩一个游戏:在一棵树上 ...
- 教你 Shiro 整合 SpringBoot,避开各种坑(山东数漫江湖)
依赖包 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-sprin ...
- js中三种定义变量 const, var, let 的区别
js中三种定义变量的方式const, var, let的区别 1.const定义的变量不可以修改,而且必须初始化. 1 const b = 2;//正确 2 // const b;//错误,必须初始化 ...
- Java开源爬虫框架crawler4j
花了两个小时把Java开源爬虫框架crawler4j文档翻译了一下,因为这几天一直在学习Java爬虫方面的知识,今天上课时突然感觉全英文可能会阻碍很多人学习的动力,刚好自己又正在接触这个爬虫框架,所以 ...
- 区块链~Merkle Tree(默克尔树)算法解析~转载
转载~Merkle Tree(默克尔树)算法解析 /*最近在看Ethereum,其中一个重要的概念是Merkle Tree,以前从来没有听说过,所以查了些资料,学习了Merkle Tree的知识,因为 ...
- deepin安装metasploit
[1]安装metasploit 1.curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/tem ...
- CreateProcess中的部分参数理解
函数原型,这里写Unicode版本 WINBASEAPIBOOLWINAPICreateProcessW( _In_opt_ LPCWSTR lpApplicationName, //可执行文件名字 ...
- selenium===selenium自动化添加日志(转)
本文转自 selenium自动化添加日志 于logging日志的介绍,主要有两大功能,一个是控制台的输出,一个是保存到本地文件 先封装logging模块,保存到common文件夹命名为logger.p ...
- docker数据管理--数据卷的备份
/* 先在宿主机创建一个备份的文 件夹, 然后将其以另外一个名字的目录挂载到容器里, 此时不管容器里,或宿主机里做什么操作, 数据都会及时更新,并得到备份. */ [root@localhost ~] ...
- Mui自定义时间格式:
Mui自定义时间格式: (function($) { $.init(); $(document).on('tap','.btn',function(){ var obj = getFormJson($ ...