CodeForces - 1221E Game With String(不平等博弈)
Alice and Bob play a game. Initially they have a string s1,s2,…,sns1,s2,…,sn, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length aa, and Bob must select a substring of length bb. It is guaranteed that a>ba>b.
For example, if s=s= ...X.. and a=3a=3, b=2b=2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s=s= ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX.
Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally.
You have to answer qq independent queries.
Input
The first line contains one integer qq (1≤q≤3⋅1051≤q≤3⋅105) — the number of queries.
The first line of each query contains two integers aa and bb (1≤b<a≤3⋅1051≤b<a≤3⋅105).
The second line of each query contains the string ss (1≤|s|≤3⋅1051≤|s|≤3⋅105), consisting of only characters . and X.
It is guaranteed that sum of all |s||s| over all queries not exceed 3⋅1053⋅105.
Output
For each test case print YES if Alice can win and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
3
3 2
XX......XX...X
4 2
X...X.X..X
5 3
.......X..X
YES
NO
YES
Note
In the first query Alice can select substring s3…s5s3…s5. After that ss turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move.
In the second query Alice can not win because she cannot even make one move.
In the third query Alice can choose substring s2…s6s2…s6. After that ss turns into .XXXXX.X..X, and Bob can't make a move after that.
题意 :T组数据 , 对于每组有一个字符串由'X'和'.'组成。现在爱丽丝和鲍勃轮流玩游戏,爱丽丝先操作。
对于每次操作爱丽丝可以把连续的a个'.'变成'X',鲍勃可以把连续的 b个'.'变成'X' 。(输入保证a大于b)
谁不能操作谁就输。
先把每段连续的‘.’处理出来存在数组num里面。
思路 :(对于题目来说鲍勃优势巨大)我们假设鲍勃先手(鲍勃先手获胜的情况是很好讨论的),把鲍勃先手获胜的情况求出来,那么对于爱丽丝来说只要操作之后的局面只要不是鲍勃先手必胜的局面那么爱丽丝就必胜。
鲍勃先手必胜的条件:
1.存在num[i]满足 b≤num[i]<a 因为b小于a所以爱丽丝能操作的num[i]鲍勃也能操作,反过来却不行。鲍勃只需要最后来操作这个满足条件的num[i]就能获胜。
2.存在num[i]满足 2*b≤num[i] 因为鲍勃先手操作一次之后可以独立出一段 b≤num[i]<a也就是条件一,根据条件一鲍勃也是必胜。
3.满足a≤num[i]<2*b的数有奇数个。因为不论是爱丽丝还是鲍勃都只能对他操作一次 ,奇数个刚好最后操作的就是鲍勃,他必胜。
爱丽丝先手只需要避免操作后变成以上三种就能获胜。
参考代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int manx = ;
char str[manx];
int a[manx];
int n;
ll x,y;
int fid()
{
for(int i=; i<=n; i++)
if(a[i]>=y&&a[i]<x) return ;
int to=,k,cnt=;
for(int i=;i<=n;i++)
{
if(a[i]>=x) cnt++;
if(a[i]>=y*) to++,k=a[i];
}
if(to>=) return ;
if(cnt%==)
{
if(to)
{
if((*x<=k&&k<=*y-+x )|| (x<=k&&k<=*y-+x))
return ;
else return ;
}
else return ;
}
else
{
if(to)
{
if(*x<=k&&k<=*y-+x) return ;
else return ;
}
else return ;
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&x,&y);
scanf("%s",str+);
int len=strlen(str+);
n=;
for(int i=;i<=len;)
{
if(str[i]=='X'){i++;continue;}
int xx=;
while(str[i]=='.') xx++,i++;
a[++n]=xx;
}
int flag=fid();
if(flag) puts("YES");
else puts("NO");
}
return ;
}
CodeForces - 1221E Game With String(不平等博弈)的更多相关文章
- CodeForces - 1221E Game With String 分类讨论
首先分析A能获胜的情况 A能获胜 当且仅当A拿完后所有剩下的都<b 所以一旦存在一个大小为X的 且 b<=X<a 则必是后手赢 当X为 a<=x<2*b 的时候 无论A或 ...
- Codeforces 1221E. Game With String
传送门 首先每一段连续的 $...$ 都是互不影响的,所以可以一段段考虑 考虑最简单的情况,此时每一段都大于等于 $a$ 并且小于 $2b$ ,那么每一段都只能放一次,胜负直接根据段数即可得到答案 考 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces 305E Playing with String 博弈
我们可以把每段连续可以选的字符看成一个游戏, 那么sg[ i ]表示连续 i 个字符可选的sg值. 然后找找第一个就好啦. #include<bits/stdc++.h> #define ...
- codeforces 455B A Lot of Games(博弈,字典树)
题目 参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269 //字典树,博弈 根据当前节点的后续来确定当前节点的状态, ...
- 【动态规划】【最短路】Codeforces 710E Generate a String
题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...
- codeforces 632C The Smallest String Concatenation
The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...
- 【Codeforces 1120C】Compress String
Codeforces 1120 C 题意:给一个串\(S\),将这个串分成\(t_1..t_m\),如果\(t_i\)在\(t_1..t_{i-1}\)中作为子串出现过,那么这个的代价是\(b\),否 ...
- Codeforces 455B A Lot of Games:博弈dp【多局游戏】
题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...
随机推荐
- jquery鼠标点击穿透的解决方法
jquery鼠标点击穿透的解决方法 <pre><div class="showcontainer" style="background:#000;dis ...
- 201871010114-李岩松《面向对象程序设计(java)》第七周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- [ch02-00] 反向传播与梯度下降的通俗解释
系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 第2章 神经网络中的三个基本概念 2.0 通俗地理解三大 ...
- supervisor服务
描述: 遇到各种各样的各种坑, 可以通过python2 的pip安装, 可以通过apt安装, 不支持python3: 如若用apt安装可能会自动启动并且加入开机自启(不保证成功),pip安装一定不会需 ...
- ubuntu 16.04上源码编译glog和gflags 编写glog-config.cmake和gflags-config.cmake | compile glog and glags on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/977f5125/,欢迎阅读! compile glog and glags on ubuntu 16.04 Series comp ...
- c# 发送邮箱,企业邮箱测试成功
今天在项目中需要实现一个发送邮箱的功能,来实现用户邮箱激活功能!!! 之前采用的是个人的邮箱进行测试,一切都是很顺利的,后来换成了公司的企业邮箱,遇到了一点小问题,问题如下: 发送邮件失败,原因:命令 ...
- MySQL锁会不会,你就差看一看
数据库锁知识 不少人在开发的时候,应该很少会注意到这些锁的问题,也很少会给程序加锁(除了库存这些对数量准确性要求极高的情况下),即使我们不会这些锁知识,我们的程序在一般情况下还是可以跑得好好的.因为这 ...
- vuejs之路由应用之一
什么是‘路由’,路由相当于一个映射,一个url地址对应一个组件,当url地址A变为url地址B,那么对应地址A的组件就会改变为对应地址B的组件.应用于spa,即:单页应用,url地址改变,它不会跳转页 ...
- HTTP基础及telnet简单命令
一.HTTP概况 20世纪90年代初期,一个主要的新兴应用即万维网(World Wide Web)登上了舞台.Web是一个引起公众注意的因特网应用.Web的应用层协议是超文本传输协议(HTTP),它是 ...
- 程序员常用6 个 Python 的日期时间库
内建的 datetime 模块 在跳转到其他库之前,让我们回顾一下如何使用 datetime 模块将日期字符串转换为 Python datetime 对象. 假设我们从 API 接受到一个日期字符串, ...