zoukankan      html  css  js  c++  java
  • 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number

    发现值域很小,而且怎么异或都不会超过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
    ",i);
    	      break;
    	    }
    	return 0;
    }
  • 相关阅读:
    The requested resource (/) is not available解决办法
    字符问题
    Unknown column in 'field list'
    table 和 div 简单布局
    css简介
    div 与 table 的优点
    瞎搞
    html
    小计--关联 复制表结构
    ddl dml dcl
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/6423632.html
Copyright © 2011-2022 走看看