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

Input
3
3 2
XX......XX...X
4 2
X...X.X..X
5 3
.......X..X
Output
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(不平等博弈)的更多相关文章

  1. CodeForces - 1221E Game With String 分类讨论

    首先分析A能获胜的情况 A能获胜 当且仅当A拿完后所有剩下的都<b 所以一旦存在一个大小为X的 且 b<=X<a 则必是后手赢 当X为 a<=x<2*b 的时候 无论A或 ...

  2. Codeforces 1221E. Game With String

    传送门 首先每一段连续的 $...$ 都是互不影响的,所以可以一段段考虑 考虑最简单的情况,此时每一段都大于等于 $a$ 并且小于 $2b$ ,那么每一段都只能放一次,胜负直接根据段数即可得到答案 考 ...

  3. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  4. Codeforces 305E Playing with String 博弈

    我们可以把每段连续可以选的字符看成一个游戏, 那么sg[ i ]表示连续 i 个字符可选的sg值. 然后找找第一个就好啦. #include<bits/stdc++.h> #define ...

  5. codeforces 455B A Lot of Games(博弈,字典树)

    题目 参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269 //字典树,博弈 根据当前节点的后续来确定当前节点的状态, ...

  6. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

  7. codeforces 632C The Smallest String Concatenation

    The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...

  8. 【Codeforces 1120C】Compress String

    Codeforces 1120 C 题意:给一个串\(S\),将这个串分成\(t_1..t_m\),如果\(t_i\)在\(t_1..t_{i-1}\)中作为子串出现过,那么这个的代价是\(b\),否 ...

  9. Codeforces 455B A Lot of Games:博弈dp【多局游戏】

    题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...

随机推荐

  1. java多线程回顾1:线程的概念与创建

    1.进程与线程的概念 现在几乎所有操作系统都支持多任务,通常一个任务就是一个程序,一个运行中的程序就是一个进程.当一个程序行时,其内部也可能在执行多个任务,进程内每一个任务的执行流,就是一个线程. 所 ...

  2. [springboot 开发单体web shop] 6. 商品分类和轮播广告展示

    商品分类&轮播广告 因最近又被困在了OSGI技术POC,更新进度有点慢,希望大家不要怪罪哦. 上节 我们实现了登录之后前端的展示,如: 接着,我们来实现左侧分类栏目的功能. ## 商品分类|P ...

  3. Download-学习资源下载

    小白求关爱:链接为本人工作中学习所碰到的,如有不对之处,请及时联系加以改正,后续仍会追加新链接地址并及时更新旧链接地址 Jdk历史版本 https://www.oracle.com/technetwo ...

  4. SpringSecurity系列之自定义登录验证成功与失败的结果处理

    一.需要自定义登录结果的场景 在我之前的文章中,做过登录验证流程的源码解析.其中比较重要的就是 当我们登录成功的时候,是由AuthenticationSuccessHandler进行登录结果处理,默认 ...

  5. nyoj 54-小明的存钱计划 (遍历 + 判断)

    54-小明的存钱计划 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:5 submit:11 题目描述: 小明的零花钱一直都是自己管理.每个月的月初妈 ...

  6. ZeroC ICE的远程调用框架 ThreadPool

    ThreadPool提供Reactor/Proactor服务,并且强偶合了Reactor(反应器)/Proactor(前摄器).不同于Reactor/Proactor使用线程池 进行事件处理的设计.如 ...

  7. 无法优化的O(n!) 算法

    旅行商问题: 有一位旅行商,他需要前往5个城市. 要前往这5个城市,同时要确保旅程最短. 对于每种顺序,他都计算总旅程,再挑选出旅程最短的路线.5个城市有120种不同的排列方式.因此,在涉及5个城市时 ...

  8. Android加载大量图片内存溢出解决办法

    当我们在做项目过程中,一遇到显示图片时,就要考虑图片的大小,所占内存的大小,原因就是Android分配给Bitmap的大小只有8M,试想想我们用手机拍照,普通的一张照片不也得1M以上,所以androi ...

  9. 2019-10-12,html+php+mysql简单留言板,作业

    php+mysql简易留言板,实现注册,登录,注销,查看留言,删除留言 1,index.html登录页面 代码: <!doctype html> <html> <head ...

  10. ctf中关于图片的隐写随笔(不全)

    ①JPG图片的结束符,十六进制常为FFD9 ②binwalk的原理是:检查常见的文件头信息,如果不符合,一定有隐藏信息.③JPG是有损压缩,PNG是无损压缩,BMP是不压缩. 隐写的基本原理:图片查看 ...