1074: You are my brother

时间限制: 1 Sec  内存限制: 128 MB

提交: 10  解决: 7

题目描述

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>
using namespace std;
#define MAX_LEN 2002
int main()
{
int a=0, b=0,n=0, count,arr[MAX_LEN],cnta, cntb,i;
while (cin >> n)
{
for (i = 0; i < MAX_LEN; i++)
arr[i] = 0;
count = 0;
while (count < n)
{
cin >> a >> b;
arr[a] = b;
count++;
}
cnta = 0,cntb = 0,i = 1;
while (arr[i] > 0 )
{
cnta ++;
i = arr[i];
}
i = 2;
while (arr[i] > 0 )
{
cntb ++;
i = arr[i];
}
if (cnta == cntb)
{
cout << "You are my brother" << endl;
}
else if (cnta > cntb)
{
cout << "You are my elder" << endl;
}
else if (cnta < cntb)
cout << "You are my younger" << endl;
}
return 0;
}

YTU 1074: You are my brother的更多相关文章

  1. fzoj1314 You are my brother

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

  2. ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)

    1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 136[Submit][Status ...

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

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

  4. lightoj 1074 spfa判断负环

     Extended Traffic Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Sub ...

  5. ytu 1058: 三角形面积(带参的宏 练习)

    1058: 三角形面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 190  Solved: 128[Submit][Status][Web Boar ...

  6. NOJ 1074 Hey Judge(DFS回溯)

    Problem 1074: Hey Judge Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format: ...

  7. 1074, "Column length too big for column 'err_solution' (max = 21845); use BLOB or TEXT instead"

    一个注意点,就是sqlalchemy 使用create_all()建表的时候,要在 create_all()所在页面import那些表的model sqlalchemy.exc.Operational ...

  8. ytu 1980:小鼠迷宫问题(DFS 深度优先搜索)

     小鼠迷宫问题 Time Limit: 2 Sec  Memory Limit: 64 MB Submit: 1  Solved: 1 [Submit][Status][Web Board] Desc ...

  9. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

随机推荐

  1. asp网页无法打开

    环境:Window 2003.IIS6.Framework1.1 .VS2003 一个WebForm项目里面包含一些asp网页  运行后发现asp页面无法访问 提示:无法找到该页 解决方案: 1. [ ...

  2. 关于对象字面量花括号{} key的类型

    原来对{}方式建立的实例化后的对象的key,理解不清,只知道,数组加不加“”,反正都是字符,现在要理解下,到底怎么回事?返回结果是 var a={}; a[1]="a"; a[&q ...

  3. 一个监控oracle数据库某个字段值变化并发送邮件报警的脚本

    talk is cheap,here is the code: #!/bin/sh export ORACLE_HOME=/u01/app/oracle/product//client_1/ expo ...

  4. PTA 04-树6 Complete Binary Search Tree (30分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/669 5-7 Complete Binary Search Tree   (30分) A ...

  5. HDU1686 计算模式串匹配的次数

    题目大意: 输入一个T,表示有T组测试数据: 每组测试数据包括一个字符串W,T,T长度大于W小于1000000,w长度小于10000,计算W匹配到T中成功的次数: 这题很明显要用KMP算法,不然很容易 ...

  6. msp430项目编程14

    msp430中项目---电子测重系统 1.hx711工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习

  7. Treasure Hunt--poj1066(最短路加判断线段的关系)

    http://poj.org/problem?id=1066 题目大意:有n条线段 他们都在这个房间里   最后有一个点代表起始位置 现在想通过墙出去  他只能爆破每个房间的中点的门   问最少的门通 ...

  8. response对象学习

    import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...

  9. Entity framework自定义字段实现思路

    ublic class MyModel { public int MyModelID { get; set; } public string FixedProperty1 { get; set; } ...

  10. jenkins修改日志级别方法

    1.jenkins日志有时候也会消耗掉很大内存,在传输时也会消耗掉大量带宽,如图,300+M的日志大小,太夸张了吧 2.修改日志级别的方法: 在配置文件里修改,重启后永久生效,配置路径:/etc/sy ...