Codeforces 845 Driving Test(模拟)

来源:互联网 发布:灯杆数据基础调研 编辑:程序博客网 时间:2024/06/05 06:13

题目地址
题意:驾照考试,你会有6个操作,问你你最少对交警说没看到几次标识来解释自己才能保证自己能过考试

  • 1、(1 a)改变车的速度为a
  • 2、(2)你超车了
  • 3、(3 a)该路段限速为a
  • 4、(4)该路段允许超车
  • 5、(5)该路段的限速取消
  • 6、(6)改路段不允许超车

思路:直接模拟(看代码注释),就唯一要注意的是有你可能改变速度后原本被判定没有超速的标识也可能要说是没看到。

#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define N 100010#define M 90010#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1e9 + 7;int main() {    cin.sync_with_stdio(false);    int n, car, cc, ans, a, b;    vector<int>v;    while (cin >> n) {        ans = 0;        cin >> a >> b;        car = b;        v.clear();        cc = 0;        for (int i = 1; i < n; i++) {            cin >> a;            if (a == 1) {                cin >> b;                car = b;                while (v.size() && v.back() < car) {//判断之前的有没有要作废的标识                    v.pop_back();                    ans++;                }            }            else if (a == 2) {                ans += cc;//加上禁止超车标识的数量                cc = 0;            }            else if (a == 3) {                cin >> b;//更新超速标识的时候也要判断之前的有没有问题                v.push_back(b);                while (v.size() && v.back() < car) {                    v.pop_back();                    ans++;                }            }            else if (a == 4) {                cc = 0;//因为取消了禁止超车的标识,所以清零            }            else if (a == 5) {                v.clear();//因为取消了限速的标识,所以清零            }            else {                cc++;//增加禁止超车的标识            }        }        cout << ans << endl;    }    return 0;}
原创粉丝点击