跳到正文

题解

题解:P14505 [NCPC 2025] km/h

ziyaojia约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P14505

版本

  1. v1当前

这道题目我们只需要维护一个最大值 maxLmaxL,接着等解除限速标志出现时输出 (⌊maxL10⌋+1)×10(\lfloor\frac{maxL}{10}\rfloor+1)\times 10 就好了,除了维护最大值应该就没有什么难的了。

AC Code:

C++
#include<bits/stdc++.h>
using namespace std;
int n,nextmax;
string s;
int main(){
    cin>>n;
    while(n--){
        cin>>s;
        if(s=="/")
           cout<<(nextmax/10+1)*10<<'\n';
        else{
            cout<<s<<'\n';
            if(s.size()==3)nextmax=max((s[0]-'0')*100+(s[1]-'0')*10+s[2]-'0',nextmax);
            else nextmax=max((s[0]-'0')*10+(s[1]-'0'),nextmax);
        }
    }
    return 0;
}
原文