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;
}

 

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