东华大学2020年程序设计竞赛(同步赛)-F(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.
题意:给你n个字符串,有两个人,每个人有两种操作字符串的方法:(1)把1变成0。(2)把长度大于1的连续0的字符串变成1。从第一个人开始,如果谁没得可改了,谁就输了。
思路:这题也怪我们考虑的太多了,还有题意也没看明白,整了还几个小时,还是太菜了。其实我们可以从一个字符串推出来,如果1的数量是奇数的情况下,就是第一个人赢,1的数量是偶数的时候,就是第二个人赢。但它现在是多个字符串,我们主要是卡这里了,题目说的是一个人可以操作任意多个字符串,我们当一个一个做的,哎 不说了。
那么多个字符串的话,第一个人可以操作所有1的个数为奇数的字符串,把1的个数变成偶数个。因为连续的0变成1再变成0,就带变第二个操作没有用,只看第一个操作就行。
所以第一个人操作完,就全部都剩偶数个1的字符串,偶数个的字符串,需要操作偶数步个操作,因为我们在一个字符串中推出来了。因为从第二个开始偶数个操作,那肯定是第一个人赢。如果没有奇数个1让第一个人操作,那么就是第二个人赢。
规律:如果有奇数个1的字符串,第一个人赢
没有的话,第二个人赢

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<string>
using namespace std;
int work(string s)
{
    int num=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1')
            num++;
    }
    if(num%2!=0)//判断个数
        return 1;//奇数个
    else
        return 0;//偶数个
}
int main ()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int f=0;
        while(n--){
            string ch;
            cin>>ch;
            f=f+work(ch);
        }
        if(f)//判断是否有
            cout<<"sdzNB"<<endl;
        else
            cout<<"kgNB"<<endl;
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值