YTU 1074: You are my brother
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的更多相关文章
- fzoj1314 You are my brother
题目描述 Little A gets to know a new friend, Little B, recently. One day, they realize that they are fam ...
- ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)
1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 177 Solved: 136[Submit][Status ...
- 远程监控显示brother数控机床数据
最近几个月公司太忙了,到现在已经连续出差两个多月了. 这个项目这要做mes系统,涉及到产品在机床的加工过程监控,然后led看板显示产品进度. 这里的主角是日本的brother数控机床,服务器按照一定频 ...
- lightoj 1074 spfa判断负环
Extended Traffic Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Sub ...
- ytu 1058: 三角形面积(带参的宏 练习)
1058: 三角形面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 190 Solved: 128[Submit][Status][Web Boar ...
- NOJ 1074 Hey Judge(DFS回溯)
Problem 1074: Hey Judge Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger IO format: ...
- 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 ...
- ytu 1980:小鼠迷宫问题(DFS 深度优先搜索)
小鼠迷宫问题 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 1 Solved: 1 [Submit][Status][Web Board] Desc ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- Dream City(线性DP)
描述 JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are n trees in the ya ...
- bzoj 1500 [NOI 2005] 维修数列
题目大意不多说了 貌似每个苦逼的acmer都要做一下这个splay树的模版题目吧 还是有很多操作的,估计够以后当模版了.... #include <cstdio> #include < ...
- android GET 请求在5.0版本的取不到数据,报IO异常兼容问题解决
使用lib类库xUtils-2.6.10.jar作为数据请求的框架,在android的5.0版会有兼容问题,取不到GET请求的数据. 但是POST没有问题,难取到数据. public static R ...
- 【HDOJ6299】Balanced Sequence(贪心)
题意:给定n个只有左右括号的序列,要求将它们重新排序使得匹配的括号对数最大. n<=1e5 s[i]<=1e5 sum s[i]<=5e6 思路: 先把每个串内部的匹配数量减去,剩下 ...
- 内存管理(——高质量程序设计语言C/C++第16章)
内存的分配方式: 1.静态存储区分配:全局变量,static变量等,在程序编译时已经分配了存储内存,在程序运行的整个期间一直存在 2.程序的堆栈上:程序的局部变量,包括程序的形参等,只存在于程序的运行 ...
- [Android] 通过GridView仿微信动态添加本地图片
原文:http://blog.csdn.net/eastmount/article/details/41808179 前面文章讲述的都是"随手拍"中图像处理的操作,此篇文章主要讲述 ...
- python学习之-- shutil模块
shutil 模块功能:文件/文件夹的复制,压缩处理模块shutil.copyfileobj(fsrc,fdst[,length]):将文件内容拷贝到另一个文件中,也可以是部分内容举例:文件复制 im ...
- loj6172 Samjia和大树(树形DP+找规律)
题目: https://loj.ac/problem/6172 分析: 首先容易得出这样的dp式子 然后发现后面那个Σ其实是两段区间,可以用总和减去中间一段区间表示,所以只要维护个前缀和就ok了 这样 ...
- Spring + RMI
服务端: RmiServer.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns= ...
- Atom列编辑快捷键
安装这个:sublime-style-column-selection,在Ubuntu下使用[Shitf]+鼠标左键选择.