題目鏈接:點擊查看
題目大意:給出 n 個 01 字符串,兩個人輪流進行遊戲,每次可以選擇任意數量的字符串,進行下列操作之一(每個字符串進行的操作可以不同):
- 選擇一個字符串,使得其中的一個 ' 1 ' 變爲 ' 0 ' , 如 10000 -> 00000
- 選擇一個字符串,使得其中連續的,數量大於 2 的 ' 0 ' 變爲一個 ' 1 ' ,如 10000 -> 11
無法操作的一方輸
題目分析:需要轉換題意,首先仔細觀察後可以發現,操作 1 和操作 2 的共同特點是,可以改變 ‘ 1 ’ 數量的奇偶性,因爲操作 1 是減少一個 1 ,而操作 2 是增加一個 1 ,最後輸的局面是 n 個字符串都是 0 ,這樣一來,我們就參照尼姆博弈的思想,不難想到當 n 個字符串中 ' 1 ' 的個數都爲偶數時爲必敗態,因爲此時你如何操作,對手只需要模仿你進行相同的操作就行,這樣無論你如何操作,對手都會進行最後一次操作,相反,如果不是必敗態時,完全可以先手將奇數的字符串都更改爲偶數的字符串,從而形成必敗態
代碼:
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int N=1e6+100;
char s[N];
int main()
{
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);
int w;
cin>>w;
while(w--)
{
int n;
scanf("%d",&n);
bool flag=true;
while(n--)
{
scanf("%s",s);
if(count(s,s+strlen(s),'1')&1)
flag=false;
}
if(flag)
puts("kgNB");
else
puts("sdzNB");
}
return 0;
}