B1. Palindrome Game (easy version)

B1. Palindrome Game (easy version)

B1.回文游戏(简易版)

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

The only difference between the easy and hard versions is that the given string 8 in the easy version is initially a palindrome, this
简单版本和硬版本之间唯一的区别是,在轻松版本中给定的字符串8最初是一个回文,如下所示

condition is not always true for the hard version.
对于硬版本来说,条件并不总是正确的。

A palindrome is a string that reads the same left to night and right to left. For example, “101101” is a palindrome, while “0101” is not.
回文是一个字符串,它从左到晚、从右到左读取相同的内容。例如,“101101”是回文,而“0101”不是。

Alice and Bob are playing a game on a string 8 (which is initially a palindrome in this version) of length n consisting of the Characters
Alice和Bob正在玩一个由字符组成的长度为n的字符串8(最初是这个版本中的回文)。

‘0’ and ‘1’. Both players take alternate turns with Alice going first.
‘0’和‘1’。两位选手轮流轮流,艾丽斯先上场。

In each turn, the player can perform one of the following operations.
在每个回合中,播放机可以执行下列操作之一。

  1. Choose anyi(1≤i≤n), where s[2] = ‘0’ and change s[i] to ‘1’. Pay 1 dollar.
    1.选择Anyi(1≤i≤n),其中s[2]=‘0’,并将s[i]改为‘1’。付一美元。

  2. Reverse the whole string, pay 0 dollars. This operation is only allowed if the string is currently not a palindrome, and the last operation
    2.反转整串,付0美元。只有当字符串当前不是回文和最后一个操作时,才允许进行此操作。

was not reverse. That is, if Alice reverses the string, then Bob can’t reverse in the next move, and vice versa.
并没有逆转。也就是说,如果Alice反转了字符串,那么Bob就不能在下一个动作中反转,反之亦然。

Reversing a string means reordering its ltters from the last to the first. For example, “01001” becomes “1 0010” after reversing.
Reversing a string means reordering its ltters from the last to the first. For example, “01001” becomes “1 0010” after reversing.

The game ends when every character of string becomes ‘1’. The player who spends minimum dollars till this point wins the game and itis a
当字符串中的每个字符都变成‘1’时,游戏就结束了。在此之前花费最少金钱的玩家赢得比赛,这是一个

draw if both spend equal dollars. If both players play optimally, output whether Alice wins, Bob wins, orifit is a draw.
如果两者花费相等,就抽签。如果双方都发挥最佳,输出是爱丽丝赢了,鲍勃赢了,奥菲特是平局。

Input
输入

The first line contains a single integert(1 < t≤10*). Then t test cases follow.
第一行包含一个整数(1<t≤10*)。然后是测试用例。

The first line of each test case contains a single integern(1≤n≤103).
每个测试用例的第一行包含一个整数(1≤n≤103)。

The second line of each test case contains the string 8 of length n, consisting of the characters ‘0’ and ‘1’. It is guaranteed that the string 8
每个测试用例的第二行包含长度n的字符串8,由字符‘0’和‘1’组成。保证字符串8

is a palindrome and contains at least one ‘0’.
是回文,至少包含一个‘0’。

Note that there is no limit on the sum of n over test cases.
注意,在测试用例上,n的和没有限制。

博弈
特殊情况中间一0、中间0外还有0、全1


int main()
{
    int n, t;
    cin >> t;
    while(t --)
    {
        int n, sum = 0;
        string s;
        bool f = 0;
        cin >> n;
        cin >> s;
        int n1 = s.length();
        if(n1 % 2 && s[n/2] == '0')
            s[n/2] = '1', f = 1;

        for(int i = 0; i < n1/2; ++ i)
            if(s[i] == '0')
                sum ++;


            if(f && sum > 0)
                cout << "ALICE" << endl;
            else if(f || !f && sum > 0)
                cout << "BOB" << endl;
            else
                cout << "DRAW" << endl;
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值