问题 : You are my brother

时间限制: 1 Sec  内存限制: 128 MB

题目描述

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

解题思路

根据所给的数对,判断1,2分别组成的链的长短。

#include <stdio.h>
#include <string.h>
int main()
{
    int n, a, b;
    int s[2010];
    while (~scanf("%d", &n))
    {
        memset(s, 0, sizeof(s));
        for (int i = 0; i < n; i++)
        {
            scanf("%d%d", &a, &b);
            s[a] = b;
        }
        a = 1;
        b = 2;
        while (s[a] && s[b])
        {
            a = s[a];
            b = s[b];
        }
        if (!s[a] && s[b])
            puts("You are my younger");
        else if (!s[a] && !s[b])
            puts("You are my brother");
        else puts("You are my elder");
    }
    return 0;
}

You are my brother的更多相关文章

  1. fzoj1314 You are my brother

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

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

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

  3. Ubuntu 安装 Brother MFC7470D 驱动

    Ubuntu 安装 Brother MFC7470D 驱动 办公室的打印机是 Brother MFC7470D ,在 Ubuntu 中安装打印机驱动时,发现没有这个型号的驱动.只有 MFC7450 的 ...

  4. FJNU 1154 Fat Brother And His Love(胖哥与女神)

    FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS   Memory Limit: 257792K [Description] [ ...

  5. FJNU 1153 Fat Brother And XOR(胖哥与异或)

    FJNU 1153 Fat Brother And XOR(胖哥与异或) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] ...

  6. FJNU 1155 Fat Brother’s prediction(胖哥的预言)

    FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  7. FJNU 1152 Fat Brother And Integer(胖哥与整数)

    FJNU 1152 Fat Brother And Integer(胖哥与整数) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题 ...

  8. FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)

    FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目 ...

  9. FJNU 1151 Fat Brother And Geometry(胖哥与几何)

    FJNU 1151 Fat Brother And Geometry(胖哥与几何) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  10. FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)

    FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术) Time Limit: 1000MS   Memory Limit: 257792K [Description ...

随机推荐

  1. box-shadow阴影覆盖问题

    “商品库”栏下方阴影被覆盖,解决方法:给“商品库”盒子加“position:relative”

  2. 1Mybatis入门--1.1单独使用jdbc编程问题总结

    1.1.1 jdbc程序 Public static void main(String[] args) { Connection connection = null; PreparedStatemen ...

  3. Light oj 1281 - New Traffic System 多状态最短路

    题目大意:有向图,新计划的地铁,有k个计划新路,利用现有的铁路.k条新路和限定只能用d条新路,找出从0到n-1的最短路径 题目思路:用dist[u][use],储存使用use条新路,到达节点u的最短路 ...

  4. .net中的设计模式---单例模式

    .net设计模式: Net设计模式实例之单例模式( Singleton Pattern)  一 : 单例模式的简介:(Brief Introduction) 单例模式(Singleton Patter ...

  5. python3+selenium入门13-操作cookie

    可以把cookie理解为自己账户的身份证.因为http协议是无状态的,上一个请求和下一个请求没有关系.但是有时需要有关联.比如登录之后,才能进行操作这样的设置.这个就是cookie在起作用.登录成功时 ...

  6. genPanel.py

    #!/usr/bin/python # -*- coding: UTF-8 -*- import os import sys import re import shutil import glob ' ...

  7. 词向量之Word2vector原理浅析

    原文地址:https://www.jianshu.com/p/b2da4d94a122 一.概述 本文主要是从deep learning for nlp课程的讲义中学习.总结google word2v ...

  8. 使用tomcat发布含有shtml文件的web程序

    平常都是使用html或jsp,当导入含有shtml的一个web项目时,向平常一样使用Jetty运行,访问到shtml文件时,直接在浏览器上显示出了源码. 查询,使用tomcat发布,修改tomcat的 ...

  9. fiddler 抓取 安卓模拟器 https包

    2017-12-12 16:47:45 星期二 需要材料: 1. fiddler 2. 逍遥模拟器 步骤: 1. fiddler->tool->Optiions...->connec ...

  10. scrapy-redis(调度器Scheduler源码分析)

    settings里面的配置:'''当下面配置了这个(scrapy-redis)时候,下面的调度器已经配置在scrapy-redis里面了'''##########连接配置######## REDIS_ ...