Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome Game (hard version)题解

瞧瞧是谁在打这自闭的div。
哦,原来是我。
C太简单就不讲了,注意离散化一下1e9的范围。

我们先来看 e a s y easy easy v e r s i o n version version,题意是给你一个回文串,你可以进行两个操作,把一个0变成1或者跳过这回合(当且仅当当前不是回文串)。
容易知道只和0的数量有关。

n = 1 , 后 手 赢 n=1,后手赢 n=1,

n = 奇 数 n=奇数 n=
因为知道最中间的元素是0,我们先拿最中间的元素。
0001000 0001000 0001000
然后第二个人不能翻转,因为这个时候是回文串,没关系,我们和他对称的选。
0111220 0111220 0111220
最后两个的时候我们进行翻转
2111222 2111222 2111222
所以知道奇数的时候先手必胜。且先手领先1个花费。

n = 偶 数 n=偶数 n=
同理,在最后一轮后手进行翻转,后手必胜。且后手领先2个花费。

再来看 h a r d hard hard v e r s i o n version version
因为这个时候不是回文串了,首先算出这个串距离回文串的距离dis。
先手天然领先后手dis的花费
当dis>2,先手赢,因为先手最多差后手2个花费
当dis=0,回到回文串的情况
当dis=1,且一共只有两个0平局
当dis=1,且一共不只两个0,先手赢,虽然在回文串的时候我们知道偶数的时候领先2,但我们可以选择最后一轮不跳过,交换先后手
当dis=2,因为存在交换先后手的骚操作,先手必胜

宝宝这题写了好久,可能老了哭哭哭哭哭哭

#include<bits/stdc++.h>
using namespace std;
int len;
char s[100005];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int cnt=0,cnt0=0;
	    scanf("%d",&len);
		scanf("%s",s+1);
		for(int i=1;i<=len;i++)if(s[i]=='1'&&s[len-i+1]=='0')cnt++;
        for(int i=1;i<=len;i++)if(s[i]=='0')cnt0++;
        if(cnt>2)printf("ALICE\n");
        else
        {
            if(cnt==0)
            {
                cnt=cnt0;
                if(cnt%2==1)
                {
                    if(cnt==1)printf("BOB\n");
                    else printf("ALICE\n");
                }
                else printf("BOB\n");
            }
            else if(cnt==1)
            {
                cnt=cnt0-cnt;
                if(cnt==0)printf("ALICE\n");
                else if(cnt%2==1)
                {
                    if(cnt==1)printf("DRAW\n");
                    else printf("ALICE\n");
                }
                else printf("ALICE\n");
            }
            else if(cnt==2)
            {
                cnt=cnt0-cnt;
                if(cnt==0)printf("ALICE\n");
                else if(cnt==1)printf("ALICE\n");
                else if(cnt%2==1)printf("ALICE\n");
                else printf("ALICE\n");
            }

        }

	}
	return 0;
}

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值