codeforces 1221E. Game With String 不平等博弈

题意 :T组数据 , 对于每组有一个字符串由'X'和'.'组成。现在爱丽丝和鲍勃轮流玩游戏,爱丽丝先操作。
对于每次操作爱丽丝可以把连续的a个'.'变成'X',鲍勃可以把连续的  b个'.'变成'X'  。(输入保证a大于b)
谁不能操作谁就输。

先把每段连续的‘.’处理出来存在数组num里面。
思路 :因为a总是大于b,所以这是一个 不平等博弈 。对于这个不平等博弈,我一来就在想先手必胜或者后手必胜的策略(我太菜了没想到)。正解:(对于题目来说鲍勃优势巨大)我们假设鲍勃先手(鲍勃先手获胜的情况是很好讨论的),把鲍勃先手获胜的情况求出来,那么对于爱丽丝来说只要操作之后的局面只要不是鲍勃先手必胜的局面那么爱丽丝就必胜。

鲍勃先手必胜的条件:

  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的数有奇数个。因为不论是爱丽丝还是鲍勃都只能对他操作一次 ,奇数个刚好最后操作的就是鲍勃,他必胜。

 爱丽丝先手只需要避免操作后变成以上三种就能获胜。

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

Copy

3
3 2
XX......XX...X
4 2
X...X.X..X
5 3
.......X..X

output

Copy

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.

 

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<cstring>
#include<math.h>
#include<map>
#include<unordered_map>
#include <vector>
using namespace std;
typedef long long  ll;
const int manx = 300100;
char str[manx];
int a[manx];
int n;
ll  x,y;///题目中的a和b
int fid()
{
    for(int i=1; i<=n; i++)
    {
        if(a[i]>=y&&a[i]<x )
            return 0;
    }
    int to=0,k,cnt=0;///大于等于2*y的数量  大于等于2*y的这个值 大于x的数量
    for(int i=1; i<=n; i++)
    {
        if(a[i]>=x)
            cnt++;
        if(a[i]>=y*2)
            to++,k=a[i];
    }
    if(to>=2)
        return  0;
    if(cnt%2==1)
    {
        if(to)
        {
            if((3*x<=k&&k<=4*y-2+x )|| (x<=k&&k<=2*y-2+x))///爱丽丝和鲍勃都可以在拿两次或者不能在拿
                return 1;
            else return 0;
        }
        else  return 1;
    }
    else
    {
        if(to)
        {
            if(2*x<=k&&k<=3*y-2+x)///爱丽丝和鲍勃都可以在拿一次
                return 1;
            else  return 0;
        }
        else  return 0;
    }

}
int main()
{
    int T ;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld", &x,&y);
        scanf("%s",str+1);
        int len =strlen (str+1 );
        n = 0;
        for(int i=1; i<= len ;)
        {
            if(str[i]=='X')
            {
                i++;
                continue ;
            }
            int xx=0;
            while(str[i]=='.' )
            {
                xx++;
                i++;
            }
            a[++n]=xx;
        }
        int  flag =fid();
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章