Codeforces 845 Driving Test(模拟)

题目地址
题意:驾照考试,你会有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|1
using 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值