博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HNUSTOJ-1257 You are my brother
阅读量:7056 次
发布时间:2019-06-28

本文共 1635 字,大约阅读时间需要 5 分钟。

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.

 

 

样例输入

51 32 43 54 65 661 32 43 54 65 76 7

样例输出

You are my elderYou are my brother
#include
#include
#include
using namespace std; int pre[2005];void Solve(){ int cnta = 0, cntb = 0, a = 1, b = 2; while(pre[a]){ cnta += 1; a = pre[a]; } while(pre[b]){ cntb += 1; 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) == 1){ int a, b; memset(pre, 0, sizeof(pre)); for(int i = 0; i < n; i++){ scanf("%d %d", &a, &b); pre[a] = b; } Solve(); }}

 

 

转载于:https://www.cnblogs.com/Pretty9/p/7406773.html

你可能感兴趣的文章
corosync+pacemaker 实现高可用集群(三)
查看>>
linux下的java开发环境
查看>>
Bootstrap使用记录
查看>>
从一场场大型网站灾难过后的BUG:根
查看>>
Linux系统下怎样利用nc命令来监控检测服务器的端口使用情况
查看>>
git命令总结
查看>>
tomcat高访问jvm配置
查看>>
谢烟客---------二进制安装MariaDB,管理关系型数据库的基本组件
查看>>
JS 判断手机浏览器
查看>>
Xcode WorkSpace静态库多项目依赖
查看>>
【C语言】 实现memset
查看>>
JS 流程设计器
查看>>
blog小记
查看>>
我的友情链接
查看>>
fileoper.py
查看>>
我的友情链接
查看>>
shell脚本将指定目录下前3天日期目录使用tar打包后并将其删除源日期目录
查看>>
类的静态成员
查看>>
osi七层模型的分类
查看>>
潍坊SEO教程之网站关键词密度
查看>>