题目大意:
现有$n(n leq 10^{6})$个int范围内正整数,现欲取其中二数进行与操作,请求最大结果.
solution:
欲解此题,必先熟悉位运算.位运算,玄学者也.现有一神奇解法,观码以解之.
code:
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<queue> #include<ctime> #include<map> #define R register #define next exnttttttttt #define debug puts("mlg") using namespace std; typedef int ll; typedef long double ld; typedef unsigned long long ull; inline ll read(); inline void write(ll x); inline void writesp(ll x); inline void writeln(ll x); ll n; ll num[1100000]; ll ans; int main(){ freopen("sword.in","r",stdin); freopen("sword.out","w",stdout); n=read(); for(R ll i=1;i<=n;i++)num[i]=read(); for(R ll i=30;i>=0;i--){ ll t=0; for(R ll j=1;j<=n;j++) if(((ans&num[j])==ans)&&(num[j]&(1<<i))) ++t; if(t>=2) ans+=(1<<i); } writeln(ans); } inline ll read(){ll x=0,t=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') t=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*t;} inline void write(ll x){if(x<0){putchar('-');x=-x;}if(x<=9){putchar(x+'0');return;}write(x/10);putchar(x%10+'0');} inline void writesp(ll x){write(x);putchar(' ');} inline void writeln(ll x){write(x);putchar(' ');}