You are my brother

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


题目描述

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

题意概括

给出数字之间的关系,问1和2的辈分关系;

解题思路

根据所给数据,搜索计算出1和2分别到祖先的距离,根据到祖先的距离然后判断出1和2的辈分关系、

代码

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<algorithm>
using namespace std;int line[2010][2010];
int dfs(int x,int num)
{int i,j;num++;for(i=0;i<=2000;i++){if(line[x][i]){return dfs(i,num);}}return num;
}
int main()
{int n;int i,j,a,b;while(scanf("%d",&n)!=EOF){memset(line,0,sizeof(line));for(i=0;i<n;i++){scanf("%d %d",&a,&b);line[a][b]=1;}a=dfs(1,0);b=dfs(2,0);if(a<b){printf("You are my younger\n");}else if(a==b){printf("You are my brother\n");}else{printf("You are my elder\n");}}return 0;
}

转载于:https://www.cnblogs.com/lanaiwanqi/p/10445723.html

You are my brother相关推荐

  1. 浅析Avicii的MV Hey Brother

    date: 2017-04-10 20:30:19 其实这篇随感早应在一个月之前就写完的,但是笔者刚从老家来到北京,需要安顿各种事情,再加上自己比较懒上班比较忙,每天晚上回到家,都是直接趴在床上睡了. ...

  2. HNUSTOJ-1257 You are my brother

    1257: You are my brother 时间限制: 1 Sec  内存限制: 128 MB 提交: 39  解决: 15 [提交][状态][讨论版] 题目描述 Little A gets t ...

  3. mfc cstring 写入文件_兄弟Brother单色激光传真一体机MFC系列不能写入此文件夹提示解决方案...

    受影响机型,所有使用ControlCenter3软件的机型,WIN10系统,基本上都受影响.包括但不限于MFC-230.MFC-7340,MFC-7450等. 错误提示: 不能写入此文件夹 <M ...

  4. 计蒜客 28437.Big brother said the calculation-线段树+二分-当前第k个位置的数 ( ACM训练联盟周赛 M)...

    M. Big brother said the calculation 通过线段树维护. 这个题和杭电的一道题几乎就是一样的题目.HDU5649.DZY Loves Sorting 题意就是一个n的排 ...

  5. dcp9030cdn定影_兄弟Brother DCP-9030CDN打印机驱动(修复DCP-9030CDN打印机连接故障)V1.0 正式版...

    兄弟Brother DCP-9030CDN打印机驱动(修复DCP-9030CDN打印机连接故障)是一款非常优秀好用的针对兄弟Brother DCP-9030CDN打印机推出专业驱动程序.使用小编带来的 ...

  6. UVA11161 Help My Brother (II)【大数+递推】

    A Fibonacci sequence is calculated by adding the previous two members of the sequence, with the firs ...

  7. UVA11760 Brother Arif, Please feed us!【bitset】

    Brother Arif is a great problemsetter. He loves grid. Also, he loves light. That's why the other pro ...

  8. Brother打印机无线连接电脑端脱机状态解决方法

    一.问题: 脱机状态显示如下,无法打印 二.解决方法: 1.解决方法一: ① 需要下载安装[网络连接修复工具] 官方下载地址: 实用程序 | 下载 | MFC-8510DN | 中国 | Brothe ...

  9. 在Windows Server 2022系统上安装 Brother MFC-7450打印机驱动

    Windows Server 2022系统,接上Brother MFC-7450 打印机,能识别出来,但是提示驱动程序无法使用(请忽视打印机图标灰色状态,因为是在打印机关机的状态下截图的.) 从打印机 ...

最新文章

  1. 信息学奥赛一本通(1307:【例1.3】高精度乘法)
  2. mysql 名次语法规则_基于sql语句的一些常用语法积累总结
  3. java 获取 classpath下的配置文件
  4. 我不是领导,如何让别人听我的话?
  5. XFBAY学习笔记=++=实验十三 交换机和路由器组合实验
  6. nginx访问日志配置及访问日志切割实战
  7. amtlib.dll被McAfee删除之后?
  8. openssl SM2签名密钥生成
  9. python opencv读取图像并生成plt文件
  10. 仿百度文库,office转pdf核心转换功能
  11. centos上使用Dropbox
  12. 华为服务器RH2288 V2 BIOS配置
  13. 华为运营商级路由器配置示例 | EVdPdNd VPLS over SRv6 TE Policy(静态配置)
  14. 小鸡啄米之React组件内部的API
  15. iOSUILable边距设置
  16. 国际象棋棋盘 java_java打印国际象棋棋盘的方法
  17. python下求特征向量与特征值
  18. 工欲善其事必先利其器--MyEclipse
  19. Q3c「最大可以支持多大容量的硬盘?」AirDisk
  20. mysql read rnd next_16.9.6. 实施rnd_next()函数

热门文章

  1. 【MySQL】(图解)快速理解内连接、外连接、左连接、右连接
  2. 【Keras】The added layer must be an instance of class Layer.
  3. 利用OpenCv读取一张图片并显示
  4. 计算机网络技术专业毕业大作业答案,计算机网络技术大作业考核要求A卷
  5. oracle 开窗子句,分析函数和开窗函数
  6. C/C++学习笔记之指针体系
  7. html5诗歌变换颜色,关于颜色的现代诗歌
  8. python模拟键盘输入字符_Python | 根据关键字符串遍历窗口 模拟键盘输入操作
  9. 【Netty】Bootstrap引导
  10. 用Python爬虫破解滑动验证码