zoukankan      html  css  js  c++  java
  • Crash CodeForces

    During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.

    Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.

    It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.

    During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.

    Input

    The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 1051 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.

    Output

    A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.

    Example

    Input
    2
    0 1
    1 1
    Output
    YES
    Input
    4
    0 1
    1 2
    1 1
    0 2
    Output
    NO
    Input
    4
    0 1
    1 1
    0 1
    0 2
    Output
    YES



    其实题目不难,理解后就是一个水题。
    如果代码不合理输出NO反则输出YES
    本菜鸟定义了一个结构体 x对应的是所交的代码数,y对应的是学号。
    (代码合理的条件:所交的代码数必须逐渐增加,必须从0开始,
    后面的对应学号的所交的代码数不能大于(0+1)
    表达能力不是很好。
    下面放代码你们应该就可以很好的理解了。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 struct node
     6 {
     7     int x,y;
     8 }qu[100010];
     9 int ans[100010];
    10 int main() {
    11     int n;
    12     while(scanf("%d",&n)!=EOF){
    13         for (int i=0 ;i<100010 ;i++) ans[i]=-1;
    14         memset(vis,0,sizeof(vis));
    15         int flag=1;
    16         for (int i=0 ;i<n ;i++){
    17             scanf("%d%d",&qu[i].x,&qu[i].y);
    18             if (ans[qu[i].y]+1>=qu[i].x){
    19                 if (qu[i].x==ans[qu[i].y]+1) ans[qu[i].y]=qu[i].x;
    20             }else {
    21                 flag=0;
    22             }
    23         }
    24         if (flag) printf("YES
    ");
    25         else printf("NO
    ");
    26     }
    27     return 0;
    28 }
    
    
  • 相关阅读:
    【初心】
    【杂题集】单题小总结
    【模板】(旧)矩阵模板
    【机智题?】【Vijos】【天平称量】
    【杂题集】【51NOD 1267】4个数和为0
    【模板】(旧)Miller Rabin 素数判定
    【杂谈】只是想想
    【杂谈】思考
    【学习?】组合和排序
    【模版】读入优化
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8511677.html
Copyright © 2011-2022 走看看