Educational Codeforces Round 76 F 折半枚举
Educational Codeforces Round 76 F 折半枚举
https://codeforces.com/contest/1257/problem/F
题意:
数组a,找到一个x使得a中每一个元素异或x后“二进制中1的个数”相同。
数组长度100,数字大小2^30。
思路:
折半枚举答案X,如分为X前15位和后15位。之后我们再枚举期望的“相同个数”是多少,通过hash看看能不能满足就好了。
代码:
#include
using namespace std;
#define X first
#define Y second
#define PB push_back
#define LL long long
#define pii pair
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<>n;
for(int i=0;i>a[i];
map,int> hash_;
const int mask=(1<<18)-1;
for(int i=0;i<(1<<18);i++){
vector t(n);
for(int j=0;j t(n),p(n);
int mx=0;
for(int j=0;j>18)^i);
mx=max(t[j],mx);
}
for(int sum=mx;sum<=30;sum++){
for(int j=0;j