You are my brother

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述

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<stdio.h>
#include<string.h>
#define MAX 2100
#define max(x,y)(x>y?x:y)
int set[MAX];
int sum,sum1,sum2;
void dfs(int beg,int end)
{
if(set[beg]==beg)
return ;
int i;
for(i=1;i<=sum;i++)
{
if(set[beg]==i)//判断是否是父节点
{
if(end==1)//如果是1的父节点 自加1
sum1++;
else //是2的父节点
sum2++;
dfs(i,end);//继续搜索
break;
}
}
}
void chu()
{
int i;
for(i=0;i<MAX;i++)
set[i]=i;
}
void shu()
{
if(sum1==sum2)
printf("You are my brother\n");
else if(sum1>sum2)
printf("You are my elder\n");
else
printf("You are my younger\n");
}
int main()
{
int n,m,j,i,k,t,s;
while(scanf("%d",&t)!=EOF)
{
chu();
sum=0;
while(t--)
{
scanf("%d%d",&n,&m);
set[n]=m;
sum=max(max(n,m),sum);
}
sum1=sum2=0;
dfs(1,1);
dfs(2,2);
shu();
}
return 0;
}

  

nyoj 282 You are my brother的更多相关文章

  1. NYOJ-289 苹果 TLE 分类: NYOJ 2013-12-29 17:52 282人阅读 评论(0) 收藏

    #include<stdio.h> struct apple{ int m; int v; }app[1010]; int money(int i,int v); int main(){ ...

  2. poj 1804 (nyoj 117)Brainman : 归并排序求逆序数

    点击打开链接 Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7810   Accepted: 4261 D ...

  3. NYOJ 1007

    在博客NYOJ 998 中已经写过计算欧拉函数的三种方法,这里不再赘述. 本题也是对欧拉函数的应用的考查,不过考查了另外一个数论基本定理:如何用欧拉函数求小于n且与n互质所有的正整数的和. 记eule ...

  4. NYOJ 998

    这道题是欧拉函数的使用,这里简要介绍下欧拉函数. 欧拉函数定义为:对于正整数n,欧拉函数是指不超过n且与n互质的正整数的个数. 欧拉函数的性质:1.设n = p1a1p2a2p3a3p4a4...pk ...

  5. NYOJ 333

    http://www.cppblog.com/RyanWang/archive/2009/07/19/90512.aspx?opt=admin 欧拉函数 E(x)表示比x小的且与x互质的正整数的个数. ...

  6. fzoj1314 You are my brother

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

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

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

  8. NYOJ 99单词拼接(有向图的欧拉(回)路)

    /* NYOJ 99单词拼接: 思路:欧拉回路或者欧拉路的搜索! 注意:是有向图的!不要当成无向图,否则在在搜索之前的判断中因为判断有无导致不必要的搜索,以致TLE! 有向图的欧拉路:abs(In[i ...

  9. nyoj 10 skiing 搜索+动归

    整整两天了,都打不开网页,是不是我提交的次数太多了? nyoj 10: #include<stdio.h> #include<string.h> ][],b[][]; int ...

随机推荐

  1. vue-cli + webpack

    vue-cli + webpack 关于vue.js vue.js是一套构建用户界面的 轻型的渐进式前端框架.它的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件.使用vue可以给你 ...

  2. 敏捷开发的价值观(转自MBAlib)

    敏捷开发的价值观 实际上敏捷开发运动在数年前就开始了,但它正式开始的标志是2001年2月的“敏捷宣言”(Agile Manifesto),这项宣言是由17位当时称之为“轻量级方法学家”所编写签署的,他 ...

  3. DB天气app冲刺第八天

    ---恢复内容开始--- 今天已经是第八天了冲刺,本来今天的ui设计已经基本成型了,今天下午设计什么的都弄好了,然后自己手贱clean了一下,可能是自己的程序的bug吧,调试没有错误,安装在模拟器上以 ...

  4. Xcode 7.3.1的模拟器路径

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Core ...

  5. 《javascript高级程序设计》对象图

    1.原型链图 2.作用域链图 3.继承

  6. skip-grant-tables:非常有用的mysql启动参数

    skip-grant-tables:非常有用的mysql启动参数   介绍一个非常有用的mysql启动参数—— --skip-grant-tables.顾名思义,就是在启动mysql时不启动grant ...

  7. MYSQL中插入数据时出现的问题:

    问题: mysql',default,default); ERROR (HY000): Incorrect string value: 解决方案: 首先查看自己的数据表情况: mysql> SH ...

  8. easyui源码翻译1.32--EasyLoader(简单加载)

    前言 扩展自$.fn.datebox.defaults,使用$.fn.datetimebox.defaults重写默认值对象.下载该插件翻译源码 源码 /** * jQuery EasyUI 1.3. ...

  9. Oracle从11.2.0.2开始,数据库补丁包是一个完整安装包(转)

    从11.2.0.2开始,数据库补丁包是一个完整安装包.也就是说:比如要打11.2.0.2的补丁包,直接用11.2.0.2包来安装就可以了,不需要像10G一样先安装数据库软件再来打补丁包. 如果已经安装 ...

  10. 微信JSSDK与录音相关的坑

    欢迎各位转载, 以让微信团队重视这些恼人的BUG. 请注明出处微信JSSDK与录音相关的坑 by lzl124631x 最近一直在做微信JSSDK与录音相关的功能开发, 遇到了各种奇尺大坑, 时不时冷 ...