zoukankan      html  css  js  c++  java
  • CF1168E Xor Permutations

    邓老师在WC2021上讲的随机做法

    考虑每次随机一个(p)中没有确定的位置(p_i),枚举每个(v)判断(v operatorname{XOR} a_i)是否已经在(q)中出现,若存在这样的(v)就令(p_i = v,q_i = v operatorname{XOR} a_i),否则就随机一个未在(p)中出现的(v)(p_i = v,q_i = v operatorname{XOR} a_i)并把原来(v operatorname{XOR} a_i)所在的位置重新设为未确定。

    #include<bits/stdc++.h>
    using namespace std;
    #define fp(i,l,r) for(register int (i)=(l);(i)<=(r);++(i))
    #define fd(i,l,r) for(register int (i)=(l);(i)>=(r);--(i))
    #define fe(i,u) for(register int (i)=front[(u)];(i);(i)=e[(i)].next)
    #define mem(a) memset((a),0,sizeof (a))
    #define O(x) cerr<<#x<<':'<<x<<endl
    inline int read(){
        int x=0,f=1;char ch=getchar();
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
        return x*f;
    }
    void wr(int x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)wr(x/10);
        putchar('0'+x%10);
    }
    mt19937 gen(20040502);
    const int MAXN=4100;
    int n,a[MAXN],A[MAXN],B[MAXN],pa[MAXN],pb[MAXN],tmp[MAXN],cnt,tmp2[MAXN],tot;
    main(){
    	n=1<<read();fp(i,1,n)a[i]=read();
    	memset(A,-1,sizeof A);memset(B,-1,sizeof B);
    	while(clock()/CLOCKS_PER_SEC<0.9){
    		mem(pa);mem(pb);cnt=tot=0;
    		fp(i,1,n)if(A[i]!=-1)pa[A[i]]=i,pb[B[i]]=i;else tmp[++cnt]=i;
    		if(!cnt){
    			puts("Shi");
    			fp(i,1,n)wr(A[i]),putchar(' ');puts("");
    			fp(i,1,n)wr(B[i]),putchar(' ');puts("");
    			return 0;
    		}
    		fp(i,0,n-1)if(!pa[i])tmp2[++tot]=i;
    		int p=tmp[gen()%cnt+1],v,t;
    		fp(i,1,tot){
    			int t=a[p]^tmp2[i];
    			if(!pb[t]){
    				A[p]=tmp2[i];B[p]=t;goto ss;
    			}
    		}
    		v=tmp2[gen()%tot+1];
    		t=a[p]^v;A[pb[t]]=B[pb[t]]=-1;B[p]=t;A[p]=v;
    		ss:;
    	}
    	puts("Fou");return 0;
    }
    
  • 相关阅读:
    ASP.NET 数据绑定常用代码及其性能分析
    替代Eval的两种方式
    C# MySQL 数据库操作类
    百度地图api经纬度气死我了!
    APP审核关于3.2.1金融资格的审核回复苹果
    ios 导航栏底部黑线隐藏
    ios 涉及到支付金额计算的相关总结
    ios 图片上传与压缩,UIImagePickerController设置中文
    ios UISegmentedControl的定制
    iOS APP应用之间的跳转
  • 原文地址:https://www.cnblogs.com/WinterSpell/p/14405470.html
Copyright © 2011-2022 走看看