nyoj 282 You are my brother
You are my brother
- 描述
-
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的更多相关文章
- 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(){ ...
- poj 1804 (nyoj 117)Brainman : 归并排序求逆序数
点击打开链接 Brainman Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7810 Accepted: 4261 D ...
- NYOJ 1007
在博客NYOJ 998 中已经写过计算欧拉函数的三种方法,这里不再赘述. 本题也是对欧拉函数的应用的考查,不过考查了另外一个数论基本定理:如何用欧拉函数求小于n且与n互质所有的正整数的和. 记eule ...
- NYOJ 998
这道题是欧拉函数的使用,这里简要介绍下欧拉函数. 欧拉函数定义为:对于正整数n,欧拉函数是指不超过n且与n互质的正整数的个数. 欧拉函数的性质:1.设n = p1a1p2a2p3a3p4a4...pk ...
- NYOJ 333
http://www.cppblog.com/RyanWang/archive/2009/07/19/90512.aspx?opt=admin 欧拉函数 E(x)表示比x小的且与x互质的正整数的个数. ...
- 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数控机床,服务器按照一定频 ...
- NYOJ 99单词拼接(有向图的欧拉(回)路)
/* NYOJ 99单词拼接: 思路:欧拉回路或者欧拉路的搜索! 注意:是有向图的!不要当成无向图,否则在在搜索之前的判断中因为判断有无导致不必要的搜索,以致TLE! 有向图的欧拉路:abs(In[i ...
- nyoj 10 skiing 搜索+动归
整整两天了,都打不开网页,是不是我提交的次数太多了? nyoj 10: #include<stdio.h> #include<string.h> ][],b[][]; int ...
随机推荐
- UIScrollView解决touchesBegan等方法不能触发的解方案
新建一个类继承自UIScrollView 并重写下面的方法 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [su ...
- javascript debut trick, using the throw to make a interrupt(breakpoint) in your program
console.log('initialize'); try { throw "breakPoint"; } catch(err) {} when I debug the extj ...
- ionic+angulajs
基于ionic+angulajs的混合开发实现地铁APP 项目源码地址:https://github.com/zhangxy1035/SubwayMap 一.项目简介 在该项目中的地铁app是基于io ...
- <一> ASP.NET Html 表单
把客户端数据发送到服务器端用<form>标签 htmlpage.html Default2.aspx.cs
- JavaScript中的Function类型浅析
1. Function类型是js中引用类型之一,每个函数实际上都是Function类型的实例对象,具有自己的属性和方法.正因为函数式对象,所以函数名实际上也是一个指向函数对象的指针. 2. 常用的函数 ...
- MySql排序性能对比
- Unity3d 调用C++的DLL
原地址:http://www.cnblogs.com/alongu3d/archive/2013/04/20/3031904.html Unity 3D 调用DLL的方法 本文转载:渡蓝的博客园 ht ...
- STL--自定义类型的排序
STL的排序太坑了,尤其是在VS2010上重载sort函数的第三个比较参数的时候. invalid operator < 这个错在写多关键字排序的时候就没有停止过. 本来想查书解决,结果各种重载 ...
- 如何在Blog中使用feedburner管理RSS订阅
http://www.cnblogs.com/procoder/archive/2010/02/12/feedburner.html
- Android 性能优化之使用MAT分析内存泄露问题
我们平常在开发Android应用程序的时候,稍有不慎就有可能产生OOM,虽然JAVA有垃圾回收机,但也不能杜绝内存泄露,内存溢出等问题,随着科技的进步,移动设备的内存也越来越大了,但由于Android ...