1.求最大/小值:max/min(a,b)和max/min_element(begin,end,cmp)cmp为可选参数
2.交换:swap(a,b)
3.求上/下一个排列:prev/next_permutation(first,last,cmp)cmp为可选参数
判断一个序列A是否是另一个序列B的一种排序:is_permutation(A.begin(), A.end(), B.begin(), B.end())
4.排序:sort(begin,end,cmp) cmp为可选参数
5.去重:unique(begin,end)
6.二分查找:lower/upper_bound(begin,end,key)上下界
7.集合操作
并集:set_union(R.begin(), R.end(), S.begin(), S.end(), inserter(ans, ans.begin()));//R∪S
交集:set_intersection(R.begin(), R.end(), S.begin(), S.end(), inserter(ans, ans.begin()));//R∩S
差集:set_difference(R.begin(), R.end(), S.begin(), S.end(), inserter(ans, ans.begin()));//R-S
对称差:set_symmetric_difference(S.begin(), S.end(), R.begin(), R.end(), inserter(ans, ans.begin()));//R⊕S
合并:merge(first1,last1,first2,last2,result,compare);
9.G++自带:
__builtin_ffs(x):返回x中最后一个为1的位是从后向前的第几位,如__builtin_ffs(0x789)=1, __builtin_ffs(0x78c)=3。
于是,__builtin_ffs(x) - 1就是x中最后一个为1的位的位置。
__builtin_popcount(x):x中1的个数。
__builtin_ctz(x):x末尾0的个数。x=0时结果未定义。
__builtin_clz(x):x前导0的个数。x=0时结果未定义。
上面的宏中x都是unsigned int型的,如果传入signed或者是char型,会被强制转换成unsigned int。
__builtin_parity(x):x中1的奇偶性。