0
点赞
收藏
分享

微信扫一扫

L2-014 列车调度(set容器)

witmy 2022-09-13 阅读 52


题目链接:​​https://pintia.cn/problem-sets/994805046380707840/problems/994805063166312448​​​ 思路:输入一个值,看当前所有轨道是否有大于前前值的,有的话替换当前轨道值,否则新增轨道 ​

#include<bits/stdc++.h>
using namespace std;
set<int>s;
int main()
{
int n,a;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
cin>>a;
if(s.empty()) s.insert(a); //如果集合为空则直接加入
else
{
if(s.lower_bound(a)!=s.end()) //如果找到了比a大的数
{
s.erase(s.lower_bound(a)); //删除比a大的数
s.insert(a); //添加
}
else s.insert(a); //否则添加
}
}
cout<<s.size()<<endl;
}
return 0;
}


举报

相关推荐

天梯赛 L2-014 列车调度 (25 分)

PTA 列车调度 python

容器-Set

STL容器-set

(六)set容器

STL【容器】| 【09】set

C++容器 - set & map

0 条评论