/ Randle /

记录详情

Wrong Answer

/in/foo.cc: In function 'int main()':
/in/foo.cc:47:7: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   v[s]=abs(v[s]-1);
   ~~~~^~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 4ms 372.0 KiB
#2 Wrong Answer 3ms 344.0 KiB
#3 Accepted 3ms 344.0 KiB
#4 Accepted 3ms 372.0 KiB
#5 Accepted 3ms 384.0 KiB
#6 Accepted 3ms 356.0 KiB
#7 Accepted 3ms 384.0 KiB
#8 Accepted 4ms 376.0 KiB
#9 Accepted 5ms 364.0 KiB
#10 Accepted 4ms 348.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=30;k>=0;k--)
		{
			//cout<<"a["<<i<<"]="<<a[i]<<"  1<<"<<k<<"="<<(1<<k)<<endl;
			if((1<<k)<a[i]&&(a[i]&(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<=30;i++)
		if(v[i])
		{
			//cout<<"v["<<i<<"]="<<(1<<i)<<endl;
		    ans+=(1<<i);
		}
	cout<<ans<<endl;
	return 0;
}

信息

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