1257: You are my brother

时间限制: 1 Sec  内存限制: 128 MB
提交: 39  解决: 15
[提交][状态][讨论版]

题目描述

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
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std; int pre[];
void Solve(){
int cnta = , cntb = , a = , b = ;
while(pre[a]){
cnta += ;
a = pre[a];
}
while(pre[b]){
cntb += ;
b = pre[b];
}
if(cnta == cntb) printf("You are my brother\n");
else printf("%s\n", cnta < cntb?"You are my younger":"You are my elder");
}
int main(){
int n;
while(scanf("%d", &n) == ){
int a, b;
memset(pre, , sizeof(pre));
for(int i = ; i < n; i++){
scanf("%d %d", &a, &b);
pre[a] = b;
}
Solve();
}
}
 

HNUSTOJ-1257 You are my brother的更多相关文章

  1. 【贪心】HDU 1257

    HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...

  2. fzoj1314 You are my brother

    题目描述 Little A gets to know a new friend, Little B, recently. One day, they realize that they are fam ...

  3. 远程监控显示brother数控机床数据

    最近几个月公司太忙了,到现在已经连续出差两个多月了. 这个项目这要做mes系统,涉及到产品在机床的加工过程监控,然后led看板显示产品进度. 这里的主角是日本的brother数控机床,服务器按照一定频 ...

  4. BZOJ 1257: [CQOI2007]余数之和sum

    1257: [CQOI2007]余数之和sum Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 3769  Solved: 1734[Submit][St ...

  5. loj 1257 (求树上每一个点到树上另一个点的最长距离)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1257 思路:首先需要用到一个知识点就是树上任一点到树上最长直径的某一个端点的距离最远, ...

  6. HDOJ 1257 (最长字序列问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  7. HDU 1257 最少拦截系统(Dilworth定理+LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  8. Ubuntu 安装 Brother MFC7470D 驱动

    Ubuntu 安装 Brother MFC7470D 驱动 办公室的打印机是 Brother MFC7470D ,在 Ubuntu 中安装打印机驱动时,发现没有这个型号的驱动.只有 MFC7450 的 ...

  9. FJNU 1154 Fat Brother And His Love(胖哥与女神)

    FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS   Memory Limit: 257792K [Description] [ ...

随机推荐

  1. MySQL概述 - 一条查询sql语句的执行过程

    Server层 连接器 建立连接.获取权限.维持和管理连接. 连接建立比较复杂,建议使用长连接 定期断开长连接 mysql_reset_connection指令 查询缓存 建议关闭,任何更新操作会此t ...

  2. JSON.parse 测试

    第一种 报错 var t = JSON.parse(""); console.log(t); 第二种 正常 var t = JSON.parse('{"AA": ...

  3. package.json文件

    http://javascript.ruanyifeng.com/nodejs/packagejson.html#toc7(copy) 通常我们使用npm init命令来创建一个npm程序时,会自动生 ...

  4. SPOJ D-query && HDU 3333 Turing Tree (线段树 && 区间不相同数个数or和 && 离线处理)

    题意 : 给出一段n个数的序列,接下来给出m个询问,询问的内容SPOJ是(L, R)这个区间内不同的数的个数,HDU是不同数的和 分析 : 一个经典的问题,思路是将所有问询区间存起来,然后按右端点排序 ...

  5. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

  6. ex1.c 补

    表达式和符号运用生疏 经常少符号 

  7. sh_02_判断年龄改进版

    sh_02_判断年龄改进版 # 输入用户年龄 age = int(input("请输入年龄:")) # 判断是否满 18 岁 (>=) if age >= 18: # ...

  8. 人脸三维建模A Morphable Model For The Synthesis Of 3D Faces(三维人脸合成的变形模型)

    Abstract摘要 In this paper, a new technique for modeling textured 3D faces is introduced. 3D faces can ...

  9. sql中left join、right join、inner join的区别

    转自https://www.cnblogs.com/pcjim/articles/799302.html left  join.right join.inner join区别 left join(左联 ...

  10. 超实用的PHP代码片段!

    摘要:本文分享了九个超级有用的PHP代码片段,当你在开发网站.应用或者博客时,利用这些代码能为你节省大量的时间.你可以直接拿来用! 此前,研发频道曾发布<直接拿来用,10个PHP代码片段> ...