Educational Codeforces Round 73 (Rated for Div. 2)E(思维,博弈)
//这道题博弈的核心就是不能让后手有一段只能放b而长度不够放a的段,并且先手要放最后一次
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int length[300007];
int main(){
ios::sync_with_stdio(false);//多组数据输入cin,cout容易超时
cin.tie(NULL);
cout.tie(NULL);
int q;
cin>>q;
while(q--){
int a,b;
cin>>a>>b;
string s;
cin>>s;
int n=s.size();
int tmp=0;
int cnt1=0,cnt2=0,cnt3=0;
int len=0;
for(int i=0;i<n;++i){
if(s[i]=='.')
++tmp;
else{//记录各个长度段的个数
if(tmp>=b&&tmp<a)
++cnt1;
else if(tmp>=a&&tmp<2*b)
++cnt2;
else if(tmp>=2*b)
++cnt3,len=tmp;
tmp=0;
}
}
if(s[n-1]=='.'){//如果有最后一段不要忘了更新
if(tmp>=b&&tmp<a)
++cnt1;
else if(tmp>=a&&tmp<2*b)
++cnt2;
else if(tmp>=2*b)
++cnt3,len=tmp;
}
if(cnt3>=2||cnt1)//如果有两段长度大于等于2b,后手可以把其中一段分割出一段长度为b留给自己最后一次放置a必输,且如果有一段长度b可以放a不能放先手必输
cout<<"NO\n";
else if(!cnt3){//如果没有长度大于等于2b的段,每段都只能容许a或者b放一次
if(cnt2&1)//如果段的个数为奇数先手必胜
cout<<"YES\n";
else//偶数后手必胜
cout<<"NO\n";
}
else if(cnt2&1){//如果只有一段大于等于2b的话,并且a~2b-1长度段的个数为奇数
if(len>=2*a&&len<a+3*b-1)//如果最长段的长度在这个范围内,先手可以把它分割成一段a~2b-1的段使得剩下所有长度段不是不够放b就是ab都可以放并且数量为偶数,此时后手必输
cout<<"YES\n";
else//反之先手必输,只要先手不能必胜后手就有办法赢
cout<<"NO\n";
}
else{//如果只有一段大于等于2b的话,并且a~2b-1长度段的个数为偶数
if(len<=a+2*b-2||len>=3*a&&len<a+4*b-1)//如果最长段的长度可以使a放置完后剩余段b都放不了,那么剩下偶数段可以放ab的先手会放最后一次,此时先手必胜,另一种情况是a放置完后可以把原本长度分割成两段,两段都可以放a并且不能放下两个b,如果让后手放置后使得一段只能放b而不能放a,后手必胜,所以此时先手必胜
cout<<"YES\n";
else
cout<<"NO\n";
}
}
return 0;
}
Educational Codeforces Round 73 (Rated for Div. 2)E(思维,博弈)的更多相关文章
- Educational Codeforces Round 73 (Rated for Div. 2)
传送门 A. 2048 Game 乱搞即可. Code #include <bits/stdc++.h> #define MP make_pair #define fi first #de ...
- Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again(DP)
链接: https://codeforces.com/contest/1221/problem/D 题意: You have a fence consisting of n vertical boar ...
- Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)
链接: https://codeforces.com/contest/1221/problem/B 题意: You are given a chess board with n rows and n ...
- Educational Codeforces Round 73 (Rated for Div. 2) C. Perfect Team
链接: https://codeforces.com/contest/1221/problem/C 题意: You may have already known that a standard ICP ...
- Educational Codeforces Round 73 (Rated for Div. 2) A. 2048 Game
链接: https://codeforces.com/contest/1221/problem/A 题意: You are playing a variation of game 2048. Init ...
- Educational Codeforces Round 73 (Rated for Div. 2)F(线段树,扫描线)
这道题里线段树用来区间更新(每次给更大的区间加上当前区间的权重),用log的复杂度加快了更新速度,也用了区间查询(查询当前区间向右直至最右中以当前区间端点向右一段区间的和中最大的那一段的和),也用lo ...
- Educational Codeforces Round 73 (Rated for Div. 2)D(DP,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[300007],b[3 ...
- C. Brutality Educational Codeforces Round 59 (Rated for Div. 2) 贪心+思维
C. Brutality time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- 请描述一下 cookies,sessionStorage 和 localStorage 的区别
原文:http://blog.csdn.net/lxcao/article/details/52809939 相同点:都存储在客户端不同点: 1.存储大小 cookie数据大小不能超过4k. sess ...
- 用Eclipse+Maven+Jetty构建Java Web开发环境(详细笔记)
(软件环境) 『系统』Windows 10 x64 『JAVA』JDK 1.8.0_91 『Eclipse』 Eclipse-oxygen 『Maven』 apache-maven-3.6.3 『Je ...
- django模块导入/函数/中间件/MVC和MTV/CSRF
目录 一:模块导入 二:函数 三:中间件 四:MVC和MTV 五:csrf 一:模块导入 第一种:继承 这里的母版更像是一个架子,子板都是定义的内容(如果多个页面中 ,存在相同的页面:这样我们可以抽到 ...
- Blockchain资源
程序源码: https://github.com/HuangFJ/pyeth https://www.jianshu.com/p/b72b4eb259b8
- js下false情况
//为false的情况 false null NaN undefined "" 0
- 【笔记2-环境配置及初始化】从0开始 独立完成企业级Java电商网站开发(服务端)
准备工作 Linux系统安装 云服务器部署 概要 申请和配置 域名的购买.解析.配置.绑定流程 用户创建实操 环境安装及部署 JDK.Tomcat.Maven下载安装及配置 vsftpd下载安装及配置 ...
- leetcode菜鸡斗智斗勇系列(9)--- Range Sum of BST
1.原题: https://leetcode.com/problems/range-sum-of-bst/ Given the root node of a binary search tree, r ...
- Django框架之登录案例
内容: (1)request.GET和request.POST (2)获取get方法提交和post方法提交的数据 一.登录案例 登录逻辑代码 def login(request): if reques ...
- python splash scrapy
python splash scrapy 1. 前言 slpash是一个渲染引擎,它有自己的api,可以直接访问splash服务的http接口,但也有对应的包python-splash方便调 ...
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 高级索引
import numpy as np x = np.array([[1, 2], [3, 4], [5, 6]]) y = x[[0,1,2], [0,1,0]] print (y) import n ...