题解:P14505 [NCPC 2025] km/h

· · 题解

题目理解

这是一道适合初学者的模拟题,理解题目要求是写出正确代码的第一步。

题目的核心信息是:

关键信息

我们可以总结出以下关键点:

思路

遇到解除限速标志时:

题目说明国家限速是一个整十的数字,并且高于所有出现过的限速。

因此,当我们遇到解除限速标志时:

我们需要找到一个高于历史最高限速的整十数。具体来说,就是找到历史最高速的下一个整十数。

举例说明:

输入:3 90 85。

速度变化:90 → 85 → 100。

可以看到,遇到解除限速标志时,速度恢复到了 100,这是高于历史最高速 90 的最小整十数。

总结:历史最高速的下一个整十限速。

当遇到数字限速标志:

当遇到数字时,处理比较简单:

上代码

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <string>
#include <bitset>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 998244353;
const int MOD1 = 1e9 + 7;
const double EPS = 1e-8;

void fastOI(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
}

ll get(ull num) {
    return ((num + 10) / 10) * 10;
}

int main() {
    fastOI();
    ll n,now_max=1,max=1;
    cin>>n;

    while (n--)
    {
        string value;
        cin>>value;
        if(value=="/"){
            ll need=get(max);
            cout<<need<<'\n';
        }else{
            if(1LL*stoi(value)>=max){
                max=stoi(value)*1LL;
            }
            now_max=stoi(value)*1LL;
            cout<<now_max<<'\n';
        }
    }
    return 0;
}