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. ubuntu - sudo in php exec

    最近写防火墙的WEB版,需要在PHP中调用linux系统命令,但是防火墙有关的执行都需要管理员权限才能执行. 在ubuntu下,Apache2的运行账户默认是www-data,默认是不能通过sudo来 ...

  2. sizeof()和strlen()在求字符串长度时的差别

    sizeof()函数输出字符串长度时会把结束符计算在内: strlen()函数输出字符串长度时不会把结束符计算在内. 如图:

  3. treeview 点击时选中节点

    private void tv_WebList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { Point clickPo ...

  4. 双缓冲(Double Buffer)原理和使用

    转自双缓冲(Double Buffer)原理和使用 一.双缓冲作用            双缓冲甚至是多缓冲,在许多情况下都很有用.一般需要使用双缓冲区的地方都是由于"生产者"和& ...

  5. 如何使用 Zend Expressive 建立 NASA 图片库?

    在本文中,我们将借助 NASA 天文图库 API,使用 Zend Expressive 建立图片库.最后的结果将显示在 AstroSplash 网站,该网站是为了文本特意搭建的.本文系 OneAPM ...

  6. Log4j配置全说明

    转载:http://zhangjunhd.blog.51cto.com/113473/21014/ 1.Log4j简介 Log4j是Apache的一个开源项目,它允许开发者以任意间隔输出日志信息.Lo ...

  7. D-Bus,kdbus和Binder

    http://blog.sina.com.cn/s/blog_4af327e10101irie.html 材料来自:The unveiling of kdbus 和 Kdbus Details .后一 ...

  8. Spring学习笔记(二)

    1.Spring MVC 返回json数据 <bean class="org.springframework.web.servlet.mvc.annotation.Annotation ...

  9. linux如何安装jdk

    一.安装 创建安装目录,在/usr/java下建立安装路径,并将文件考到该路径下: # mkdir /usr/java 1.jdk-6u11-linux-i586.bin 这个是自解压的文件,在lin ...

  10. SSH框架中配置Hibernate使用proxool连接池

    一.导入proxool.jar包 案例用的是proxool-0.8.3.jar,一般通过MyEclipse配置的SSH都会包含这个jar,如果没有,就去网上搜下下载导入就好了. 二.新建Proxool ...