感想:奇奇怪怪的STL和奇奇怪怪的折半
#include<iostream> #include<cstdio> #include<cmath> #include<map> #include<queue> #include<algorithm> #include<cstring> #include<string> using namespace std; map<vector<int>,int> m; int a[100001]={0}; int Min(int X,int Y){ return X<Y ? X : Y; } int Max(int X,int Y){ return X>Y ? X : Y; } inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } int pop_count(int shu){ int ans=0; while(shu!=0){ if(shu%2==1) ans++; shu/=2; } return ans; } int main(){ int n; ios::sync_with_stdio(false); n=read(); for(int i=1;i<=n;i++) a[i]=read(); //前15位 for(int i=0;i<(1<<15);i++){ vector<int> v; int bz=pop_count((a[1]>>15)^i); for(int j=2;j<=n;j++) v.push_back(bz-pop_count((a[j]>>15)^i)); m[v]=i; } //后15位 for(int i=0;i<(1<<15);i++){ vector<int> v; int bz=pop_count(((a[1]-((a[1]>>15)<<15)))^i); for(int j=2;j<=n;j++) v.push_back(pop_count(((a[j]-((a[j]>>15)<<15)))^i)-bz); if(m[v]!=0){ printf("%d",(m[v]<<15)+i); return 0; } } printf("-1"); return 0; }
(我是真没想到map还能这么用)