标签:思维
2 2 1 2 23 1 3 1 4 5 2 1 1 3 1 4 5 2 1 1 3 1 4 5 2 1 2 1
1 2 1 2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int cnt[32],pos[32],mp[32][32];
void solve(int x)
{
int i,j;
int t=0,p=0;
while(x)
{
if(x&1)
{
cnt[p]++;
pos[t++]=p;
}
p++;
x>>=1;
}
for(i=0;i<t;i++)
for(j=i+1;j<t;j++)
mp[pos[j]][pos[i]]++;
}
int main()
{
int tes,n;
int i,j,x;
scanf("%d",&tes);
while(tes--)
{
scanf("%d",&n);
memset(cnt,0,sizeof(cnt));
memset(pos,0,sizeof(pos));
memset(mp,0,sizeof(mp));
while(n--)
{
scanf("%d",&x);
solve(x);
}
for(i=0;i<32;i++)
{
cnt[i]%=3;
for(j=0;j<32;j++)
mp[i][j]%=3;
}
int res1,res2;
res1=res2=0;
int poi=-1;
for(i=31;i>=0;i--)
{
res1=res1*2;
if(cnt[i]==2)
{
cnt[i]--;
res1+=1;
}
else if(cnt[i]==1&&poi==-1)
{
cnt[i]--;
poi=i;
res1+=1;
}
else if(cnt[i]==1&&mp[poi][i]==1)
{
cnt[i]--;
res1+=1;
}
}
for(i=31;i>=0;i--)
{
res2=res2*2;
if(cnt[i])
{
res2+=1;
}
}
if(res1>res2)
{
int tmp=res1;
res1=res2;
res2=tmp;
}
printf("%d %d\n",res1,res2);
}
return 0;
}
/*
5
111 111 111 234 5453
328MS 232K
*/
HDU 3972 1 M possible(思维),布布扣,bubuko.com
标签:思维
原文地址:http://blog.csdn.net/coraline_m/article/details/27329497