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. php 5.5使用 array_column的方法

    <pre>php 5.5使用 array_column的方法</pre> <pre> public function array_column($input, $c ...

  2. python—mariadb自动部署主从

    import configparser import os def config_mariadb_yum(): exists = os.path.exists('/etc/yum.repos.d/ma ...

  3. java多线程回顾4:线程通信

    1.线程的协调运行 线程的协调运行有一个经典案例,即生产者和消费者问题. 假设有一个货架,生产者往货架上放货物,消费者从货架上取货物. 为了方便讲解,制定一个规则,生产者每放上一个货物,消费者就得取走 ...

  4. [ERROR]Unable to locate package

    刚更换了DNS,需要更新下apt-get $ apt-get update

  5. 做HTML静态页面时遇到的问题总结

    1. 如果所示,问题:“首页”和“闲置”文字部分位于table中部 解决方法:需要取消vertical-align:middle属性,将其设置为vertical-align:top,并将文本的高度改为 ...

  6. Andorid开发中遇到的问题

    最近开始学习开发Android App,找了本教程,学了一些基本知识后,就开始着手做一个例子. 我始终觉得在做中学,可能会稍微快一点.很快,一个具有初步功能的App被我撸出来了. 在模拟器上运行,我发 ...

  7. Curl elasticsearch

    1. 查看cluster state curl localhost:9200/_cluster/health?pretty Or curl localhost:9200/_cluster/health ...

  8. 【NHOI2018】衰减

    [解题思路] 显然这题并不难,由于数据范围较小,完全可以用DFS解决. 从原数开始每次变异的图谱,每次记录住当前的路径. 当找到1时就可以输出并回溯了. 小技巧:printf和scanf可以提高输出输 ...

  9. Android View 的添加绘制流程 (二)

    概述 上一篇 Android DecorView 与 Activity 绑定原理分析 分析了在调用 setContentView 之后,DecorView 是如何与 activity 关联在一起的,最 ...

  10. JSP内置对象详解及示例

    目录 JSP 内置对象 out request response config application session pageContext page exception JSP 内置对象 jsp一 ...