UOJ354 新年的投票

task 3:

int n=15;
int val[1<<16];
int e[1<<16][16];

signed main()
{
	freopen("vote3.ans","w",stdout);
	int V=1e8;
	For(i,0,n-1) e[1<<i][i]=V,e[0][i]=-V,val[1<<i]=V;
	For(j,1,n-1){
		For(s,0,(1<<n)-1)
			if(__builtin_popcount(s)==j){
				int tmp=val[s]-1;
				tmp=tmp/(n-j);
				tmp=min(tmp,V);
				assert(tmp<=V);
				assert(tmp>0);
				For(k,0,n-1)
					if(!(s>>k&1)){
						e[s|(1<<k)][k]=tmp;
						e[s][k]=-tmp;
						val[s|(1<<k)]+=tmp;
						val[s]-=tmp;
					}
			//	cout<<"s: "<<s<<" "<<val[s]<<"\n";
				assert(val[s]>0);
			}
	}
	For(i,0,n-1){
		For(s,0,(1<<n)-1)
			if(!(s>>i&1)){
				int t=(s|(1<<i));
				int res=e[t][i];
				if(__builtin_popcount(t)&1) res=-res;
				cout<<-res<<" ";
			}
		cout<<"\n";
	}
	return 0;
}

task 2

int n=15;

int xs[15];

signed main()
{
	freopen("vote2.ans","w",stdout);
	For(i,1,15){
		int k=__lg(i);
	//	cerr<<"i,k "<<i<<" "<<k<<"\n";
		For(s,0,(1<<15)-1)
			if(!(s>>(i-1)&1)){
				For(j,0,4) xs[j]=0;
				For(j,1,15) xs[__lg(j)]^=(s>>(j-1)&1);
				bool f1=0;
				For(j,0,k-1) if(xs[j]) f1=1;
				if(!f1) cout<<((__builtin_popcount(s)&1)^(1^xs[k]));
				else cout<<(i&1);
			}
		cout<<"\n";
	}
	return 0;
}

task 4:

int n=12,k=7;
// [2,3,4,5,6,7,8,9]
// 2.5,....8.5
int f[1<<15],g[1<<15];

int sgn(int x){
	return __builtin_parity(x)?-1:1;
}

int res[1<<12|5],st[1<<12|5],tp;

signed main()
{
	freopen("vote4.ans","w",stdout);
	f[0]=1;
	for(int i=5;i<=17;i+=2){
		cerr<<"i: "<<i<<"\n";
		For(s,0,(1<<n)-1) if(f[s]){
			g[s]+=f[s]*i;
			For(j,0,n-1) g[s|(1<<j)]-=f[s]*2;
		}
		For(s,0,(1<<n)-1) f[s]=g[s],g[s]=0;
	}
	
	int okc=0;
	For(s,0,(1<<n)-1){
		int sum=f[0];
		for(int i=s;i;i=(i-1)&s) sum+=f[i];
		if((sum>0&&sgn(s)>0) || (sum<0&&sgn(s)<0)) ++okc;
	}
	cerr<<"okc "<<okc<<"\n";
	cerr<<"noc "<<((1<<n)-1)-okc<<"\n";
	
	int V=100000000;
	For(s,0,(1<<n)-1) if(__builtin_popcount(s)==k){
		tp=0;
		for(int t=s;t;t=(t-1)&s) st[tp++]=t;
		st[tp++]=0;
		reverse(st,st+tp);
		Rep(i,tp-1,0){
			int t=st[i];
			int u=(s^t);
			if(f[s^t]){
				res[s^t]=-f[s^t];
				if(res[s^t]<-V) res[s^t]=-V;
				if(res[s^t]>V) res[s^t]=V;
				for(int x=t;x;x=(x-1)&t) 
					f[u|x]+=res[s^t]*sgn(x);
				int x=0;
					f[u|x]+=res[s^t]*sgn(x);
			}
		}
		//cout<<"F0 "<<f[0]<<"\n";
		For(i,0,tp-1) cout<<res[st[i]]<<" ",res[st[i]]=0; cout<<"\n";
	}
//	For(i,0,(1<<n)-1) cout<<f[i]<<" "; cout<<" f\n";
	return 0;
}
posted @ 2024-08-04 11:19  Rainbow_qwq  阅读(64)  评论(0编辑  收藏  举报