博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ningbo [1218] You are my brother(注意数组的大小)
阅读量:4036 次
发布时间:2019-05-24

本文共 1572 字,大约阅读时间需要 5 分钟。

1、

2、题目:

  • [1218] You are my brother

  • 时间限制: 1000 ms 内存限制: 131072 K
  • 问题描述
  • 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.
  • 样例输入
  • 51 32 43 54 65 661 32 43 54 65 76 7
  • 样例输出
  • You are my elderYou are my brother
  • 提示
  • 来源
  • 辽宁省赛2010
3、AC代码:

#include
#include
#include
#include
#include
using namespace std;int f[3005];int main(){ int n,a,b; while(scanf("%d",&n)!=EOF) { memset(f,-1,sizeof(f)); for(int i=1;i<=n;i++) { scanf("%d%d",&a,&b); f[a]=b; } int p=1; int sum=0; while(f[p]!=-1) { sum++; p=f[p]; } p=2; int count=0; while(f[p]!=-1) { count++; p=f[p]; } if(count>sum) printf("You are my younger\n"); else if(count

转载地址:http://ogddi.baihongyu.com/

你可能感兴趣的文章
浅析:setsockopt()改善程序的健壮性
查看>>
关于对象赋值及返回临时对象过程中的构造与析构
查看>>
VS 2005 CRT函数的安全性增强版本
查看>>
SQL 多表联合查询
查看>>
Visual Studio 2010:C++0x新特性
查看>>
drwtsn32.exe和adplus.vbs进行dump文件抓取
查看>>
cppcheck c++静态代码检查
查看>>
在C++中使用Lua
查看>>
在Dll中调用自身的位图资源
查看>>
C++中使用Mongo执行count和distinct运算
查看>>
一些socket的编程经验
查看>>
socket编程中select的使用
查看>>
C++获取文件大小常用技巧分享
查看>>
关于AIS编码解码的两个小问题
查看>>
GitHub 万星推荐:黑客成长技术清单
查看>>
可以在线C++编译的工具站点
查看>>
关于无人驾驶的过去、现在以及未来,看这篇文章就够了!
查看>>
所谓的进步和提升,就是完成认知升级
查看>>
昨夜今晨最大八卦终于坐实——人类首次直接探测到了引力波
查看>>
如何优雅、机智地和新公司谈薪水?
查看>>