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 ...
随机推荐
- 小程序开发-Step1
先申请一个小程序 https://mp.weixin.qq.com/wxopen/waregister?action=step1 根据以上链接步骤一步一步来,认识字就可以完成,没什么特殊的 申请成功之 ...
- Springboot/cloud 项目突然出现许多Failed to read artifact descriptor, 或者无法解析
由于jar 包冲突,还是什么原因引起 在仓库下即:.m2 下面执行以下命令(cmd) for /r %i in (*.lastUpdated) do del %i 然后对项目用maven update ...
- invalidate和requestLayout
Invalidate:To farce a view to draw,call invalidate().——摘自View类源码从上面这句话看出,invalidate方法会执行draw过程,重绘Vie ...
- 20165234 2017-2018-2《Java程序设计》课程总结
2017-2018-2<Java程序设计>课程总结 一.作业链接汇总 每周作业链接 预备作业一:我期望的师生关系 预备作业二:学习基础和C语言基础调查 预备作业三:Linux安装及学习 第 ...
- Markdown超链接及脚注
Markdown链接及脚注 [时间:2017-02] [状态:Open] [关键词:markdown,标记语言,页内链接,超链接,脚注] 本文内容来自Markdown 11种基本语法,仅对其中我不熟悉 ...
- 论文笔记:Deep Residual Learning
之前提到,深度神经网络在训练中容易遇到梯度消失/爆炸的问题,这个问题产生的根源详见之前的读书笔记.在 Batch Normalization 中,我们将输入数据由激活函数的收敛区调整到梯度较大的区域, ...
- ES6学习笔记四(类和对象)
{ // 构造函数和实例 class Parent{ constructor(name='mukewan'){ this.name=name; } } let v_parent=new Parent( ...
- VC,VB操作XML
TCHAR buffer[MAX_PATH] = {}; ::GetModuleFileName(NULL, buffer, MAX_PATH); CString strPath = buffer; ...
- delete指针以后应赋值为NULL
delete p后,只是释放了指针中存放的地址中的内存空间.但是指针变量p仍然存在(即指针p本身所占有的内存),且p中存放的地址还是原来的地址. 例如: 对一个非空指针delete后,若没有将p赋为N ...
- 词向量之Word2vector原理浅析
原文地址:https://www.jianshu.com/p/b2da4d94a122 一.概述 本文主要是从deep learning for nlp课程的讲义中学习.总结google word2v ...