Educational Codeforces Round 73 (Rated for Div. 2) E. Game With String 思维博弈 好题(2500)

传送门

文章目录

题意:

在这里插入图片描述

思路:

我们将每一段 . . .拿出来看成若干段,将其分成以下四种情况:
( 1 ) l e n < b (1)len<b (1)len<b
( 2 ) b ≤ l e n < a (2)b\le len<a (2)blen<a
( 3 ) a ≤ l e n < 2 ∗ b (3)a\le len<2*b (3)alen<2b
( 4 ) l e n ≥ 2 ∗ b (4)len\ge 2*b (4)len2b
我们依次考虑这四种线段。
( 1 ) (1) (1)首先线段 1 1 1是无用线段,不需要考虑。
( 2 ) (2) (2)线段 2 2 2只能由后手操作,如果存在线段 2 2 2,那么后手必胜。
证明:因为先抛去线段 2 2 2,使用其他的线段进行游戏,结果无非两个,先手不能操作和后手不能操作。先手不能操作那么后手必胜,后手不能操作的时候说明线段已经用光了,这个时候拿出线段 2 2 2来使得后手仍能操作,后手必胜。
( 3 ) (3) (3)线段 3 3 3二者只能操作一次,那么如果只存在线段 3 3 3的话,由偶数段线段 3 3 3的时候后手必胜,有奇数段线段 3 3 3的时候先手必胜。
比较显然,不加以证明。
( 4 ) (4) (4)线段 4 4 4如果存在至少两条的时候,后手必胜。
证明:由于后手可以从线段 4 4 4中截出来一段线段 2 2 2,所以先手动的时候最多能操作一个线段 4 4 4来使得其不能被分出来线段 2 2 2,所以如果有至少两个线段 4 4 4那么后手必胜。
现在讨论只有一个线段 4 4 4的时候怎么办。
首先先手肯定是要操作线段 4 4 4的,不然被后手拿出来线段 2 2 2就必败了。那么我们可以枚举先手将线段 4 4 4分成的两段的长度,如果两段中有一段是线段 2 2 2或者线段 4 4 4,那么肯定是不行的。那么只剩下线段 1 1 1和线段 3 3 3了,只需要判断以下线段 3 3 3的个数即可。

// Problem: E. Game With String
// Contest: Codeforces - Educational Codeforces Round 73 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1221/problem/E
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int a,b,n;
char s[N];

int get(int cnt) {
	if(cnt<b) return 1;
	else if(cnt<a) return 2;
	else if(cnt<2*b) return 3;
	else return 4;
}

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	
	int _; scanf("%d",&_);
	while(_--) {
		int x,y,z; x=y=z=0;
		scanf("%d%d%s",&a,&b,s+1);
		n=strlen(s+1);
		int len=0;
		for(int i=1;i<=n;i++) {
			if(s[i]=='X') continue;
			int cnt=0;
			while(i<=n&&s[i]=='.') i++,cnt++; i--;
			if(cnt<b) continue;
			else if(cnt<a) x++;
			else if(cnt<2*b) y++;
			else z++,len=cnt;
		}
		if(x||z>1) puts("NO");
		else {
			if(!z) {
				if(y%2==0) puts("NO");
				else puts("YES");
			} else {
				bool flag=false;
				for(int st=0;st+a<=len;st++) {
					int l=st,r=len-st-a;
					int id1=get(l),id2=get(r);
					if(id1==2||id2==2||id1==4||id2==4) continue;
					int now=y+(id1==3)+(id2==3);
					if(now%2==0) {
						flag=true;
						break;
					}
				}
				if(flag) puts("YES");
				else puts("NO");
			}
		}
	}
	


	return 0;
}
/*

*/









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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值