东华大学2020年程序设计竞赛(同步赛)F.A Simple Game

87 篇文章 0 订阅
17 篇文章 0 订阅

东华大学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

简单博弈~
我们首先考虑只有一个字符串的博弈策略~
不难发现,对当前操作的那个人字符串如果只包含 0 0 0,那么必输,不理解的可以推理一下 00 00 00 或者 000 000 000 的情况,后面多个 0 0 0 的情况都可以通过前面递推 ,那么最优策略就很简单了,只要把 1 1 1 转化为 0 0 0 即可,尽可能让对面操作时仅剩下 0 0 0 就一定能赢~
知道最优博弈策略后就很简单了,对一个字符串只需判断其含字符 1 1 1 的个数即可,奇数 A l i c e Alice Alice 赢,反之则输~
那么推广到多个字符串怎么判断呢,我是构造了几个简单的例子发现其实和一个字符串答案一样,只要存在一个含奇数个 1 1 1 的字符串 A l i c e Alice Alice 一定能赢。我是这么理解的, A l i c e Alice Alice 可以与 B o b Bob Bob 先把偶数字符串走掉,此时最后肯定是 A l i c e Alice Alice 先手,她只需要操作那个含奇数个 1 1 1 的字符串就能赢了~
AC代码如下:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int f(string s){
    int cnt=0;
    for(char c:s)
        if(c=='1') cnt++;
    return cnt%2;
}

 int main(){
    int t,n;
    cin>>t;
    while(t--){
       string s;
       cin>>n;
       int num=0;
       for(int i=0;i<n;i++) cin>>s,num+=f(s);
       if(num) puts("sdzNB");
       else puts("kgNB");
    }
 }
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺 崽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值