A Simple Game

题目描述
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;
}

博弈

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值