• Educational Codeforces Round 85 A. Level Statistics(水题)


    output
    standard output

    Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.

    All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by 11 . If he manages to finish the level successfully then the number of clears increases by 11 as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).

    Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.

    So he peeked at the stats nn times and wrote down nn pairs of integers — (p1,c1),(p2,c2),,(pn,cn)(p1,c1),(p2,c2),…,(pn,cn) , where pipi is the number of plays at the ii -th moment of time and cici is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).

    Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.

    Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.

    Help him to check the correctness of his records.

    For your convenience you have to answer multiple independent test cases.

    Input

    The first line contains a single integer TT (1T500)(1≤T≤500) — the number of test cases.

    The first line of each test case contains a single integer nn (1n1001≤n≤100 ) — the number of moments of time Polycarp peeked at the stats.

    Each of the next nn lines contains two integers pipi and cici (0pi,ci10000≤pi,ci≤1000 ) — the number of plays and the number of clears of the level at the ii -th moment of time.

    Note that the stats are given in chronological order.

    Output

    For each test case print a single line.

    If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES".

    Otherwise, print "NO".

    You can print each letter in any case (upper or lower).

    Example
    Input
    Copy
    6
    3
    0 0
    1 1
    1 2
    2
    1 0
    1000 3
    4
    10 1
    15 2
    10 2
    15 2
    1
    765 432
    2
    4 4
    4 3
    5
    0 0
    1 0
    1 0
    1 0
    1 0
    
    Output
    Copy
    NO
    YES
    NO
    YES
    NO
    YES
    关于条件判断的。这里用x y记录当前的数对,a b记录上一组数对。只有x-a>=0且y-b>=0(通过人数和参加人数不减少)且x-a>=y-b(新增的参加人数不会比新增的通过人数少)且x>=y(累计参加人数多于累计通过人数)同时满足才可。注意特判初始的情况。
    别忘更新a和b。
    #include <bits/stdc++.h>
    using namespace std;
    int n;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int a,b,x,y;
            int i;
            scanf("%d",&n);
            bool flag=1;
            for(i=1;i<=n;i++)
            {
                scanf("%d%d",&x,&y);
                if(i==1)
                {
                    a=x,b=y;
                    if(x<y)flag=0;
                    continue;
                }
                if(!(  x-a>=0 && y-b>=0 && x-a>=y-b && x>=y && a>=b  ))
                {
                    flag=0;
                }
                a=x,b=y;//别忘了更新 
            }
            if(flag)cout<<"YES";
            else cout<<"NO";
            cout<<endl;
        }
        return 0;
     } 
  • 相关阅读:
    ajax
    文件下载--getOutputStream输出二进制字符
    文件上传功能实现代码
    java动态生成验证码
    项目中用到的jar包简介(2)
    python字符串的常见操作
    python切片使用方法(超详细)
    for循环结合range使用方法
    python使用while循环实现九九乘法表
    石家庄云修科技有限公司
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12678289.html
Copyright © 2020-2023  润新知