HNUSTOJ-1257 You are my brother
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的更多相关文章
- 【贪心】HDU 1257
HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...
- 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数控机床,服务器按照一定频 ...
- BZOJ 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3769 Solved: 1734[Submit][St ...
- loj 1257 (求树上每一个点到树上另一个点的最长距离)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1257 思路:首先需要用到一个知识点就是树上任一点到树上最长直径的某一个端点的距离最远, ...
- HDOJ 1257 (最长字序列问题)
http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memo ...
- HDU 1257 最少拦截系统(Dilworth定理+LIS)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 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] [ ...
随机推荐
- end of sleepyhead
- 解决eclipse部署maven项目无法导入lib的问题
eclipse版本为2018-12(4.10.0) 1.默认tomcat的server配置 改成: 2.项目部署 按上面的配置,项目会部署到你配置的本地tomcat的webapps目录下. 部署了项目 ...
- 创建ThreadFactory实例的多种方式
spring的CustomizableThreadFactory guava的MoreExecutors.platformThreadFactory()静态方法 guava的ThreadFactory ...
- html area标签 语法
html area标签 语法 作用:带有可点击区域的图像映射 说明:<img> 中的 usemap 属性可引用 <map> 中的 id 或 name 属性(由浏览器决定),所以 ...
- 详细讲解Android中的Message的源码
相信大家对于Android中的Handler是在为熟悉不过了,但是要知道,Handler就其本身而言只是一个壳子,真正在内部起到作用的是Message这个类,对于Message这个类,相信大家也不会陌 ...
- flask中request对象获取参数的方法
从当前request获取内容: method: 起始行,元数据 host: 起始行,元数据 path: 起始行,元数据 environ: 其中的 SERVER_PROTOCOL 是起始行,元数据 he ...
- 20175221 《Java程序设计》第10周学习总结
20175221 <Java程序设计>第10周学习总结 教材学习内容总结 第十二章主要内容有: 进程与线程 进程是程序的一次动态执行过程,它对应了从代码加载.执行至执行完毕的一个完整过 ...
- linux 上使用libxls读和使用xlslib写excel的方法简介
读取excel文件:libxls-1.4.0.zip下载地址:http://sourceforge.net/projects/libxls/安装方法: ./configure make make ...
- iptables添加、删除端口
简洁才是王道, 下面是添加一个udp端口,端口号8566,即接收到8566端口的所有udp包 /sbin/iptables -I INPUT -p udp --dport -j ACCEPT 要删除这 ...
- webpack插件之webpack-dev-server
webpack插件之webpack-dev-server webpack插件 自动化 webpack-dev-server 现在只需要使用 npm run build指令就可以自动打包,并自动处理好 ...