【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his ...

发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了。

复杂度O(k*1024)。

#include<cstdio>
#include<cstring>
using namespace std;
int n,k,x,cnts[1110],tmpcnts[1110];
int main()
{
//	freopen("c.in","r",stdin);
	int X;
	scanf("%d%d%d",&n,&k,&x);
	for(int i=1;i<=n;++i)
	  {
	  	scanf("%d",&X);
	  	++cnts[X];
	  }
	for(int i=1;i<=k;++i)
	  {
	  	memset(tmpcnts,0,sizeof(tmpcnts));
	  	int now=0;
	  	for(int j=0;j<=1023;++j)
	  	  {
	  	  	int t=cnts[j];
	  	  	if(now%2==0)
	  	      {
	  	    	cnts[j]/=2;
	  	    	tmpcnts[j^x]+=(t-cnts[j]);
	  		  }
	  		else
	  		  {
	  		  	cnts[j]=(cnts[j]+1)/2;
	  		  	tmpcnts[j^x]+=(t-cnts[j]);
	  		  }
	  		now+=t;
	  	  }
	  	for(int j=0;j<=1023;++j)
	  	  cnts[j]+=tmpcnts[j];
	  }
	for(int i=1023;i>=0;--i)
	  if(cnts[i])
	    {
	      printf("%d ",i);
	      break;
	    }
	for(int i=0;i<=1023;++i)
	  if(cnts[i])
	    {
	      printf("%d\n",i);
	      break;
	    }
	return 0;
}

转载于:https://www.cnblogs.com/autsky-jadek/p/6423632.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值