用到了set中的lower_bound()函数,在这篇文章里有解释:
编程中琐碎的小知识点-持续更新
//跟蜘蛛纸牌类似
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
set<int>se;
for(int i=0;i<n;i++)
{
int k;
scanf("%d",&k);
set<int>::iterator it=se.lower_bound(k);
if(it!=se.end())
{
se.erase(it);//删掉原来的
se.insert(k);//更新这个更小的值
}
else
se.insert(k);//直接加上这个值
}
cout<<se.size()<<endl;
return 0;
}