- vector 去重
auto it=unique(v.begin(),v.end());
v.erase(it)- nth_element
nth_element(a+1,a+k,a+n+1) 执行后:
a[k] 为第 k 小数。
比 a[k] 小的数跑到前面,比 a[k] 大的数跑到后面。
然后 a[k] 查询第 k 小,要访问比 a[k] 小的就遍历 1…k。
复杂度 ,本质上就是不完全快排。
- max/min 强制转化
#include<bits/stdc++.h>
using namespace std;
int a=1,b=3,c=5;
long long d=4,e=2,t;
int main()
{
t=min<long long>({a,b,c,d,e});//可以直接<long long>
printf("%lld",t);
return 0;
}- 重载运算符
struct Node{
int x,y;
bool operator < (const Node &a)const{
return x<a.x;
}
};- 字符串拼接
s+=t 时间复杂度为
a=s+t 事件复杂度为 。
- set
易错点:set 的二分查找千万不能写数组查找的形式否则会变成 !
要写 st.lower_bound(st.begin(),st.end(),x)。
- auto
auto 是随便的数据类型。
auto 在 c++11 以后的版本可用。
auto 返回的是随便的类型。随着自变量的类型而改变。