全排列-next_permutation
sort(arr, arr + k);//排序
ll len = unique(arr, arr + k) - arr;//去重,与sort一起用
do
{
} while (next_permutation(arr, arr + len));//全排列
二分查找-lower_bound
stack<int> sta;
vector<int> v;
vector<int>::iterator it;
it = lower_bound(v.begin(), v.end(), sta.top()); //三个参数分别为数组头迭代器,尾迭代器
//要查找的参数值,返回数组中第一个大于或等于被查数的值的迭代器
ll val = lower_bound(v.begin(), v.end(), sta.top()) - v.begin();
//此时返回数组中第一个大于或等于被查数的值
该函数时判断n的二进制中有多少个1
int n = 15; //二进制为1111
cout<<__builtin_popcount(n)<<endl;//输出4
该函数是判断n的二进制中1的个数的奇偶性
int n = 15;//二进制为1111
int m = 7;//111
cout<<__builtin_parity(n)<<endl;//偶数个,输出0
cout<<__builtin_parity(m)<<endl;//奇数个,输出1
该函数判断n的二进制末尾最后一个1的位置,从一开始
int n = 1;//1
int m = 8;//1000
cout<<__builtin_ffs(n)<<endl;//输出1
cout<<__builtin_ffs(m)<<endl;//输出4
该函数判断n的二进制末尾后面0的个数,当n为0时,和n的类型有关
int n = 1;//1
int m = 8;//1000
cout<<__builtin_ctzll(n)<<endl;//输出0
cout<<__builtin_ctz(m)<<endl;//输出3