You are my brother
问题 : You are my brother
时间限制: 1 Sec 内存限制: 128 MB
题目描述
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
解题思路
根据所给的数对,判断1,2分别组成的链的长短。
#include <stdio.h>
#include <string.h>
int main()
{
int n, a, b;
int s[2010];
while (~scanf("%d", &n))
{
memset(s, 0, sizeof(s));
for (int i = 0; i < n; i++)
{
scanf("%d%d", &a, &b);
s[a] = b;
}
a = 1;
b = 2;
while (s[a] && s[b])
{
a = s[a];
b = s[b];
}
if (!s[a] && s[b])
puts("You are my younger");
else if (!s[a] && !s[b])
puts("You are my brother");
else puts("You are my elder");
}
return 0;
}You are my brother的更多相关文章
- fzoj1314 You are my brother
题目描述 Little A gets to know a new friend, Little B, recently. One day, they realize that they are fam ...
- 远程监控显示brother数控机床数据
最近几个月公司太忙了,到现在已经连续出差两个多月了. 这个项目这要做mes系统,涉及到产品在机床的加工过程监控,然后led看板显示产品进度. 这里的主角是日本的brother数控机床,服务器按照一定频 ...
- Ubuntu 安装 Brother MFC7470D 驱动
Ubuntu 安装 Brother MFC7470D 驱动 办公室的打印机是 Brother MFC7470D ,在 Ubuntu 中安装打印机驱动时,发现没有这个型号的驱动.只有 MFC7450 的 ...
- FJNU 1154 Fat Brother And His Love(胖哥与女神)
FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS Memory Limit: 257792K [Description] [ ...
- FJNU 1153 Fat Brother And XOR(胖哥与异或)
FJNU 1153 Fat Brother And XOR(胖哥与异或) Time Limit: 1000MS Memory Limit: 257792K [Description] [题目描述] ...
- FJNU 1155 Fat Brother’s prediction(胖哥的预言)
FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS Memory Limit: 257792K [Description] [ ...
- FJNU 1152 Fat Brother And Integer(胖哥与整数)
FJNU 1152 Fat Brother And Integer(胖哥与整数) Time Limit: 1000MS Memory Limit: 257792K [Description] [题 ...
- FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)
FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS Memory Limit: 257792K [Description] [题目 ...
- FJNU 1151 Fat Brother And Geometry(胖哥与几何)
FJNU 1151 Fat Brother And Geometry(胖哥与几何) Time Limit: 1000MS Memory Limit: 257792K [Description] [ ...
- FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)
FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术) Time Limit: 1000MS Memory Limit: 257792K [Description ...
随机推荐
- awk基本用法
1 简介 awk实质是一种编程语言,基本作用在于查找和替换. 2 基本用法 有文本名称为:awk.txt 内容为: john.wang male 30 021-111111 lucy.yang f ...
- 20165234 《Java程序设计》第二周课下作业
1. 教材代码完成情况测试P14 把100改为自己的后四位学号,编译运行Kernighan.java 代码的功能是从给定一个数字,实现从1依次加到此数的和. 如下是我用命令行实现代码的编译与运行. 2 ...
- glCleatDepth
opengl里面的深度缓存 在现实生活中,一个实心物体挡在另外一个实心物体的前面, 后面的那个物体有部分会被遮盖掉 那么opengl里面如何模拟这个情况呢? 每个物体的每个像素都有一个深度缓存的值( ...
- Python笔记 【无序】 【一】
----------- r'原始数据' 为了输入[c:\n\d\r\] 代码: ...
- 狼抓兔子 BZOJ- 1001 最小割
https://www.lydsy.com/JudgeOnline/problem.php?id=1001 一个图,问你花费多少才能把到终点的所有边堵住... 就是求一个最小割,把$(1,1)$和$( ...
- Mudo C++网络库第八章学习笔记
muduo网络库的设计与实现 muduo是基于Reactor模式的C++网络库; Reactor的关键结构 Reactor最核心的是事件分发机制, 即将IO multiplexing拿到IO事件分发给 ...
- Alpha 冲刺 (5/10)
目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺5 团队部分 后敬甲(组长) 过去两天完成了哪些任务 文字描述 最近事情有点多,只是跟进了下进度,写了写博客 接下来 ...
- T-SQL GROUP BY子句 分组查询
SQL Server GROUP BY子句与SELECT语句协作使用,以将相同的数据分组. GROUP BY子句位于SELECT语句中的WHERE子句之后,位于ORDER BY子句之前. 语法 以下是 ...
- Lua学习总结
由于一些工作上的需要,开始对Lua的学习.之前有JavaScript的基础,而且两者都是脚本语言,所以本总结旨在列出与JavaScript不同的地方,方便后续的回顾和学习.下面进入正题吧! 1.注释 ...
- 1-HTML Attributes
下表列举了常用的Html属性 Attribute Description alt Specifies an alternative text for an image, when the image ...