题目链接
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);
}
}