为什么UKE?
查看原帖
为什么UKE?
363353
pearchen楼主2023/7/5 10:00

//From:[CF1257F]Make Them Similar

#include<bits/stdc++.h>
using namespace std;

const int MAXN=110;
int n;
int a[MAXN];
map<vector<int>,int> mp;
int p=(1<<15)-1;

int popcount(int x);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
    }

    for(int i=0;i<(1<<15);++i)
    {
        vector<int> fir;
        int f=popcount((a[1]>>15)^i);
        for(int j=2;j<=n;++j)
        {
            fir.push_back(popcount((a[j]>>15)^i)-f);
        }
        mp[fir]=i;
    }

    for(int i=0;i<(1<<15);++i)
    {
        vector<int> las;
        int l=popcount((a[1]&p)^i);
        for(int j=2;j<=n;++j)
        {
            las.push_back(l-popcount((a[j]&p)^i));
        }
        if(mp.count(las))
        {
            cout<<(mp[las]<<15)+i<<endl;
            return 0;  
        }
    }
    cout<<-1<<endl;
    return 0;
}

int popcount(int x)
{
    int c=0;
    while(x)
    {
        ++c;
        x&=(x-1);
    }
    return c;
}
2023/7/5 10:00
加载中...