1.next_permutaion(a,a+n):
用于一个数组的全排列(从当前数组状况开始,所以要真正生成全排列之前先排序)。用法如下。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 int a[3]; 6 a[0]=1;a[1]=2;a[2]=3; 7 do{ 8 cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl; 9 }while (next_permutation(a,a+3)); 10 }
2.__builtin_popcount(i):
用于计算i的二进制位数中共有几个1.
3.bitset<maxn>:
相当于一个数组,但每位只能为0或1.暴力时用到可以增加效率。
4.mt19937:
生成随机数(范围比rand()更大,可以不指定也可以指定)。使用方法如下:
1 #include <bits/stdc++.h> 2 using namespace std; 3 mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); 4 int main(){ 5 uniform_int_distribution<int> dist(0,1000); 6 cout<<mt()<<" "; //不指定范围 7 cout<<dist(mt)<<" "; //限制范围 8 return 0; 9 }
5.shuffle:
用于随机排列数组。用法: shuffle(a,a+maxn,mt);
6.rotate:
讲第二个参数到第三个参数区间内(左闭右开)的元素移到第一个参数之前。用法: rotate(b,b+n-1,b+n);
7.__builtin_clz(i):
计算i的二进制有多少个前导零。