Cattle off winter training camp 2 --- I

Topic Portal

(I may have been infected with exclusive or phobia ...)

The best way to overcome fear is to ... Oliver!

The only reason the giant water ... do not come out of a question is stuck in the more God (sha) odd (que) F-topic,

Has shown signs directly out of a long time to prepare is preparing to board spanning tree line and then, suddenly found the edge a little bit more ... (people scared silly) but also because of the mentality of cards F card explosion threw ... (naked excuses)

Because the master is not good for bit operations, so there is no way like the solution to a problem that write (n + logv) algorithm ... (QWQ)

On the code:

#include <iostream>
#include <algorithm>
#define MAX 100010
#define ll long long
using namespace std;
ll a[MAX];
ll k[MAX];
int len=0;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(i==0||a[i]!=a[i-1])
		k[len++]=a[i];
	}
	ll ans;
	for(int i=0;i<=31;i++)
	{
		int f0=0,f1=0;
		for(int j=0;j<len;j++)
		{
			if((k[j]&(1<<i))==0)
			{
				f0=1;
			}
			else
			f1=1;
		}
		if(f0&&f1)
		{
			ans=i;
			break;
		}
	}
	cout<<1ll*(1ll<<ans)*1ll*(len-1);
	return 0;
}

Throw official explanations:
Here Insert Picture Description

Official Code

Published 30 original articles · won praise 9 · views 1302

Guess you like

Origin blog.csdn.net/Zhang_sir00/article/details/104208510