题目描述
Alice and Bob play a game.Initially they have n binary strings (a string which consists of zeroes and ones). They take alternating turns, and Alice is moving first. During each turn, the player has to choose several (at least one) strings and do one of the following operations (you can perform different operations on different strings):
1:choose a character ‘1’, and replace it with ‘0’.
2:choose a contiguous substring consisting only of characters ‘0’, and replace it with ‘1’(The length of the substring is at least 2).
For example, if s = “11000”,then after operation 1 s can turn into “01000” or “10000”. if s = “11000”, then after operation 2 s can turn into “1110”, “1101” or “111”.
Whoever is unable to choose,loses.You have to determine who wins if they both play optimally.
输入描述:
The first line contains one integer t (1≤ t ≤100) — the number of test cases. Then the test cases follow.
For each test case, the first line contains one integern(1 ≤ n ≤ 10).
There arenlines following, the i-th of which contains a binary string of length not more than 1000.
输出描述:
For each test case print sdzNB if Alice can win and kgNB otherwise.
示例1
输入
复制
2
2
00
1
3
11
11
11
输出
复制
sdzNB
kgNB
说明
For the 1st test case,Alice can choose the second string and perform operation 1 on it,after which the string turns into “0”.Then Bob can only perform operation 2 on the first string.
For the 2nd test case,nothing to say,KGNB.
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int m;
string a[500];
while(n--)
{
cin>>m;
int i;
int count=0,cnt2=0;
for(i=0;i<m;i++)
{
cin>>a[i];
}
for(i=0;i<m;i++)
{
for(int j=0;j<a[i].size();j++)
{
if(a[i][j]=='1')
count++;
}
if(count%2!=0) cnt2++;
}
if(!cnt2) cout<<"kgNB"<<endl ;
else cout<<"sdzNB"<<endl;
}
return 0;
}
博弈