acm-(异或、博弈)CF Difficult Problems GameGame

10 篇文章 0 订阅
4 篇文章 0 订阅

题面
传送门
c n t i cnt_i cnti表示第 i i i位为1的数的数量。

c n t i % 2 = 0 cnt_i\%2=0 cnti%2=0的时候,容易发现无论怎样博弈最终两方的异或值在这一位上的情况一定是相同的,故这一位不能决定胜负。

考虑一个最大的 i = k i=k i=k使得 c n t i % 2 = = 1 cnt_i\%2==1 cnti%2==1,如果 c n t k − 1 2 % 2 = = 0 \frac {cnt_k-1}2\%2==0 2cntk1%2==0,容易发现先手必赢,而当 c n t k − 1 2 % 2 = = 1 \frac{cnt_k-1}2\%2==1 2cntk1%2==1时,又要分两种情况,若 n % 2 = = 0 n\%2==0 n%2==0,先手必输,否则先手必赢(先手第一步先拿走一个0即可)。

当然如果所有的 c n t i % 2 = 0 cnt_i\%2=0 cnti%2=0均成立,那么就是平局。

int cnt[maxlog];
int main(){
	int t=rd();
	while(t--){
		int n=rd();
		memset(cnt,0,sizeof(cnt));
		FOR(i,1,n+1){
			int u=rd();
			FOR(i,0,maxlog){
				if((1<<i)&u){
					cnt[i]++;
				}
			}
		}
		int ans=0;
		ROF(i,maxlog-1,0){
			if(cnt[i]&1){
				if(!(((cnt[i]-1)>>1)&1))ans=1;
				else{
					if(n&1)ans=2;
					else ans=1;
				}
				break;
			}
		}
		if(!ans)wrsn("DRAW");else if(ans==1)wrsn("WIN");else wrsn("LOSE");
	}
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值