202杭电多校第十场1010

题目链接
Nim game博弈
参考题解:Alice 第一轮取完后,Bob 上来取取同行或者同列必败,因此一定取不同行不同列的。本题性质允许行交
换列交换,不妨设 Alice 取 (1, 1), Bob 取 (2, 2)。
这样除 (3, 3) 外, 剩下的每个格子都是不论后续局面如何, 谁第一个取最后一颗石子谁必败。 因
此 (3, 3) 整堆与其他每堆除一颗石子外的整堆构成一个普通 nim 游戏, 即后手必败当且仅当
((1, 2) ) 1) ⊕ ((1, 3) ) 1) ⊕ ((2, 1) ) 1) ⊕ ((2, 3) ) 1) ⊕ ((3, 1) ) 1) ⊕ ((3, 2) ) 1) ⊕ (3, 3) = 0。
⊕:取异或

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
typedef double db;
const int mod=1e9+7;
const int maxn=1e6;
const double eps=0.00000001;
ll a[10][10];
int main(){
	int t;
	cin>>t;
	while(t--){
		ll sum=0;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				scanf("%lld",&a[i][j]);
				sum^=(a[i][j]-1);
			}
		}
		int ans=0;
		bool f;
		for(register int i=0;i<3;++i){
			for(register int j=0;j<3;++j){
				f=1;
				for(register int k=0;k<3;++k){
					if(i!=k)
					for(register int h=0;h<3;++h){
						if(j!=h)
						if(sum==((a[i][j]-1)^(a[k][h]-1)^(a[3-i-k][3-j-h]-1)^a[3-i-k][3-j-h])){
							f=false;
							break;
						}
					}
					if(!f) break;
				}
				ans+=f;
			}
		}
		printf("%d\n",ans);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值