HNUSTOJ-1257 You are my brother
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.
样例输入
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<iostream>
#include<cstring>
#include<cstdio> using namespace std; int pre[];
void Solve(){
int cnta = , cntb = , a = , b = ;
while(pre[a]){
cnta += ;
a = pre[a];
}
while(pre[b]){
cntb += ;
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) == ){
int a, b;
memset(pre, , sizeof(pre));
for(int i = ; i < n; i++){
scanf("%d %d", &a, &b);
pre[a] = b;
}
Solve();
}
}
HNUSTOJ-1257 You are my brother的更多相关文章
- 【贪心】HDU 1257
HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...
- 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数控机床,服务器按照一定频 ...
- BZOJ 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3769 Solved: 1734[Submit][St ...
- loj 1257 (求树上每一个点到树上另一个点的最长距离)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1257 思路:首先需要用到一个知识点就是树上任一点到树上最长直径的某一个端点的距离最远, ...
- HDOJ 1257 (最长字序列问题)
http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memo ...
- HDU 1257 最少拦截系统(Dilworth定理+LIS)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- Ubuntu 安装 Brother MFC7470D 驱动
Ubuntu 安装 Brother MFC7470D 驱动 办公室的打印机是 Brother MFC7470D ,在 Ubuntu 中安装打印机驱动时,发现没有这个型号的驱动.只有 MFC7450 的 ...
- FJNU 1154 Fat Brother And His Love(胖哥与女神)
FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS Memory Limit: 257792K [Description] [ ...
随机推荐
- vue学习-day01(vue指令)
目录: 1.什么是vue.js 2.为什么要学习前端的流行框架 3.框架和库的区别 4.后端MVC和前端的MVVM的区别 5.vue.js的基本代码--hollo world代 ...
- Composite UI Application Block(CAB)
序言 资料 https://www.cnblogs.com/lglruirui/archive/2010/06/21/1761737.html?tdsourcetag=s_pcqq_aiomsg ht ...
- POJ 2528 Mayor’s posters (线段树段替换 && 离散化)
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...
- Shell中Bash的基本功能(二)
1 历史命令 1)历史命令的查看[root@localhost ~]# history [选项] [历史命令保存文件]选项:-c: 清空历史命令-w: 把缓存中的历史命令写入历史命令保存文件.如果不手 ...
- sh_07_continue
sh_07_continue i = 0 while i < 10: # continue 某一条件满足时,不执行后续重复的代码 # i == 3 if i == 3: # 注意:在循环中,如果 ...
- [THUSC2017]大魔法师:线段树
分析 在线段树上用\(4 \times 4\)的矩阵打标记. 代码 #include <bits/stdc++.h> #define rin(i,a,b) for(register int ...
- Windows 下安装Apache web服务器
1.Apache 服务器的下载 进入下载页面:http://httpd.apache.org/download.cgi 为提高下载速度,镜像选择清华大学的服务器(http://mirrors.tuna ...
- es之对文档进行更新操作
5.7.1:更新整个文档 ES中并不存在所谓的更新操作,而是用新文档替换旧文档: 在内部,Elasticsearch已经标记旧文档为删除并添加了一个完整的新文档并建立索引.旧版本文档不会立即消失 ,但 ...
- Window、Linux查看本机外网ip
前言 我们上网用的IP并不一定是本机网卡的IP地址,由于公网IP地址稀少,国内绝大多数电脑上网,一般都是通过拨号或者端口映射.多个内网地址映射到一个公网地址来实现上网的. 目录 1.查看本机网卡ip ...
- 关于项目中的一些经验:封装activity、service的基类,封装数据对象
经验一,将几个页面公用的数据,和方法进行封装,形成一个baseActivity的类: package com.ctbri.weather.control; import java.util.Array ...