/ Randle /

记录详情

Wrong Answer

/in/foo.cc: In function 'int main()':
/in/foo.cc:32:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(((unsigned int)1<<k)<a[i]&&(a[i]&((unsigned int)1<<k)))
       ~~~~~~~~~~~~~~~~~~~~^~~~~
/in/foo.cc:46:7: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   v[s]=abs(v[s]-1);
   ~~~~^~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 2ms 312.0 KiB
#2 Wrong Answer 2ms 308.0 KiB
#3 Accepted 2ms 324.0 KiB
#4 Accepted 2ms 308.0 KiB
#5 Accepted 2ms 440.0 KiB
#6 Accepted 1ms 308.0 KiB
#7 Accepted 1ms 312.0 KiB
#8 Accepted 1ms 308.0 KiB
#9 Accepted 1ms 328.0 KiB
#10 Accepted 1ms 304.0 KiB

代码

#include<bits/stdc++.h>
using namespace std;
int n,a[1001],v[32];
long long ans=0;
inline const void read(int &a)
{
	a=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
bool com(int a,int b)
{
	return a>b;
}
int main()
{
	int i,k,s;
	memset(v,0,sizeof(v));
	read(n);
	for(i=1;i<=n;i++) read(a[i]);
	sort(a+1,a+1+n,com);
	for(i=1;i<=n;i++)
	{
		for(k=31;k>=0;k--)
		{
			//cout<<"a["<<i<<"]="<<a[i]<<"  1<<"<<k<<"="<<(1<<k)<<endl;
			if(((unsigned int)1<<k)<a[i]&&(a[i]&((unsigned int)1<<k)))
			{
				//cout<<"i="<<i<<" k="<<k<<endl;
				s=k;
				if(!v[k])
				{
					//cout<<"i="<<i<<" k="<<k<<endl;
				    v[k]=1;
				    break;
				}
		    }
		}
		//cout<<"i="<<i<<"  a["<<i<<"]="<<a[i]<<" k="<<k<<endl;
		if(k==-1)
		v[s]=abs(v[s]-1);
	}
	//for(int i=1;i<=30;i++)
	//if(v[i])
	//cout<<i<<' ';
	//cout<<endl; 
	for(i=0;i<=31;i++)
		if(v[i])
		{
			//cout<<"v["<<i<<"]="<<(1<<i)<<endl;
		    ans+=((unsigned int)1<<i);
		}
	cout<<ans<<endl;
	return 0;
}

信息

递交者
类型
递交
题目
奇数异或(国家集训队)
题目数据
下载
语言
C++
递交时间
2017-10-10 19:48:22
评测时间
2017-10-10 19:48:22
评测机
分数
90
总耗时
21ms
峰值内存
440.0 KiB