• Codeforces 807 A Is it rated?


    A. Is it rated?
    time limit per test             
    2 seconds
    memory limit per test       
    256 megabytes
    input      
    standard input
    output
    standard output

    Is it rated?

    Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.

    Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.

    It's known that if at least one participant's rating has changed, then the round was rated for sure.

    It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.

    In this problem, you should not make any other assumptions about the rating system.

    Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.

    Input

    The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants.

    Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.

    Output

    If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".

    Examples
    input
    6
    3060 3060
    2194 2194
    2876 2903
    2624 2624
    3007 2991
    2884 2884
    output
    rated
    input
    4
    1500 1500
    1300 1300
    1200 1200
    1400 1400
    output
    unrated
    input
    5
    3123 3123
    2777 2777
    2246 2246
    2246 2246
    1699 1699
    output
    maybe
    Note

    In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.

    In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.

    In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.

    如果前后两个值有改变,输出rated

    否则,如果序列非增,输出maybe 

            否则,输出unrated

    #include<cstdio>
    using namespace std;
    int n,a[1001],b[1001],last=5000;
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            if(a[i]!=b[i]) {  printf("rated"); return 0; }
        }
        for(int i=2;i<=n;i++)
            if(a[i]>a[i-1]) { printf("unrated"); return 0; }
        printf("maybe"); return 0;
    }

    WA1:错误代码:

    原因:如果所有的a等于b,那么中间a也有可能大于上一个a

    #include<cstdio>
    using namespace std;
    int n,a,b,last=5000;
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&a,&b);
            if(a!=b) {  printf("rated"); return 0; }
            if(a>last) { printf("unrated"); return 0; }
            last=a;
        }
        printf("maybe"); return 0;
    }

    WA2:判断序列非增时,要从第2个开始,因为第1个前面是0,一定增

     

  • 相关阅读:
    Spring Boot日志管理
    JProfiler
    JProfiler学习笔记
    jprofiler安装图解
    方便!C++ builder快捷键大全
    QuickFix/N简介
    QuickFIX/N入门:(三)如何配置QuickFIX/N
    java自带线程池和队列详细讲解
    SQLYog快捷键大全
    DBCP连接池配置参数说明
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/6839908.html
Copyright © 2020-2023  润新知