几个小tips
1.若两个数的异或等于其最大公约数,则也必等于其差绝对值
2.几种离散化(为啥这么简单的东西还需要板子..)
1 2 3 4 5 6 7 8 9 10 11 12
|
vector<int> v; int (int x){ return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; } int main(){ for(int i = 1;i <= n;i++){ v.push_back(a[i]); } sort(v.begin, v.end()); v.erase(unique(v.begin(), v.end()), v.end()); a[i] = getid(a[i]); }
|
1 2 3 4 5 6 7 8
|
for(int i = 1;i <= n;i++){ tmp[i] = s[i]; } sort(tmp + 1,tmp + n + 1); int len = unique(tmp + 1,tmp + 1 + n) - tmp - 1; for(int i = 1;i <= n;i++){ s[i] = lower_bound(tmp + 1,tmp + len + 1,s[i]) - tmp; }
|
1 2
|
__builtin_popcount(n) 返回1的二进制中有多少个1 next_permutation(a + 1, a + n + 1);
|
近期评论