【打CF,学算法——二星级】CodeForces 417B Crash (水题)
来源:互联网 发布:fins超出数组 编辑:程序博客网 时间:2024/05/16 03:35
【CF简介】
提交链接:CF 417B
题面:
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 toA, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the samex.
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 numberx(x > 0) of the participant with numberk, then the testing system has a solution with numberx - 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.
The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the followingn lines contains two integers separated by spacex andk (0 ≤ x ≤ 105;1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
20 11 1
YES
40 11 21 10 2
NO
40 11 10 10 2
YES
题意:
每个人有唯一的id标识,且每个人有多条提交记录,问给定的序列是否满足,每个人的提交记录是符合时间顺序的。题意不是很明了,简单地说就是每条记录出现前,其对应提交的id为x,那么x-1(0特殊)始终存在,则为合法。
解题:
用一个vector数组记录每个id当前出现的最大的提交id,如果新的数据小于等于对应人的最大id+1,都是合法的,否则是非法的。
代码:
#include <iostream>#include <algorithm>#include <cmath>#include <iomanip>#include <cstdio>#include <vector>using namespace std;vector <int> v[100005];int main(){ int n,a,b;scanf("%d",&n);bool flag=1; for(int i=0;i<n;i++){scanf("%d%d",&a,&b);if(a==0){if(v[b].size()==0)v[b].push_back(a);}else{if(v[b].size()==0){flag=0;break;}else{if(v[b][v[b].size()-1]<a-1){flag=0;break;}else{if(a==v[b][v[b].size()-1]+1)v[b].push_back(a);}}}}if(flag)printf("YES\n");elseprintf("NO\n");return 0;}
- 【打CF,学算法——二星级】CodeForces 417B Crash (水题)
- 【打CF,学算法——二星级】Codeforces 22B Bargaining Table(区域和)
- 【打CF,学算法——二星级】CodeForces 237B Young Table (构造)
- 【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)
- 【打CF,学算法——一星级】CodeForces 227B Effective Approach (水题)
- 【打CF,学算法——二星级】CodeForces 96B Lucky Numbers (构造/dfs)
- 【打CF,学算法——二星级】Codeforces 699B - One Bomb (技巧)
- 【打CF,学算法——二星级】Codeforces 703B Mishka and trip (统计)
- 【打CF,学算法——二星级】Codeforces 705B Spider Man (简单博弈)
- 【打CF,学算法——二星级】CodeForces 417C Football(构造)
- 【打CF,学算法——二星级】CodeForces 282C XOR and OR (观察)
- 【打CF,学算法——二星级】CodeForces 626C Block Towers(暴力/二分)
- 【打CF,学算法——二星级】Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- 【打CF,学算法——二星级】CF 520B Two Buttons
- 【打CF,学算法——二星级】CodeForces 374A Inna and Pink Pony (水题/坑题)
- 【打CF,学算法——一星级】CodeForces 318A (水题)
- 【打CF,学算法——一星级】CodeForces 74A Room Leader (水题)
- 【打CF,学算法——一星级】CodeForces 617D Polyline(水题)
- Android之ViewPager引导页(动态加载指示器)
- 看完就彻底懂了session和cookie
- poj1979
- javascript中DOM元素的属性方法
- IQKeyboardManager 自动处理键盘回收第三方
- 【打CF,学算法——二星级】CodeForces 417B Crash (水题)
- Linux 2.4.x内核软中断机制
- 使用Docker实现持续集成
- 众数问题
- 九度OJ 1040 求前10000个素数
- 14javascript操作style对象
- Selenium IDE录制的百度搜索并点击结果测试用例回放报错
- 流媒体技术问答
- Informix常用操作方法命令