理解题面
这是道初学者基础题,首先了解题目要干什么,才能写出能过的代码,我们读题(关键区已粗体):
你完全记不住国家限速,只知道它是一个整十的数字。
现在,当你依次经过每一个标志——无论是限速还是解除限速——你需要仅根据目前为止看到的标志,判断自己能够合法行驶的最高车速。
解析信息
从题面可以得出的信息有
- 我们只需要判断两种状态 第一种 数字 第二种
/也就是解除限速 - 判断当前的最大合法速度,我需要分类讨论
思路
当时是l时
从题面得知 你完全记不住国家限速,只知道它是一个整十的数字。 从这里我们总结出第一种状态也就是解除限速时,你只需寻找一个输入过最大的数最近的整十数字
我们拿样举例子
输入n=3 =90 =85 =/
的时最大时速90->85->100 不难发现当=/的时候你只需要找出里面最大的速度找出他最近的整十数字就行了
得出结论找现有最大时速最近的整十数字
当是数字时
你只需要更新最大合法时速的状态就行了
接下来上代码,码风良好。
#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;
}提交你就会发现
你Accepted了