zoukankan      html  css  js  c++  java
  • CodeForces

    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 (1q31051≤q≤3⋅105) — the number of queries.

    The first line of each query contains two integers aa and bb (1b<a31051≤b<a≤3⋅105).

    The second line of each query contains the string ss (1|s|31051≤|s|≤3⋅105), consisting of only characters . and X.

    It is guaranteed that sum of all |s||s| over all queries not exceed 31053⋅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 s3s5s3…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 s2s6s2…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 = 300100;
    char str[manx];
    int a[manx];
    int n;
    ll  x,y;
    int fid()
    {
        for(int i=1; i<=n; i++)
            if(a[i]>=y&&a[i]<x) return 0;
        int to=0,k,cnt=0;
        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) puts("YES");
            else puts("NO");
        }
        return 0;
    }
     
    View Code
  • 相关阅读:
    AI boxfilter
    AI AdaBoost算法
    AI Haar特征
    15.VUE学习之-表单中使用key唯一令牌解决表单值混乱问题
    14.VUE学习之-v-if v-else-if语法在网站注册中的实际应用讲解
    13.VUE学习之控制行内样式
    12.2 VUE学习之-if判断,实践加减input里的值
    12.1.VUE学习之-循环li,if判断示例讲解class中应用表达式
    10.VUE学习之使用lodash库减少watch对后台请求的压力
    09.VUE学习之watch监听属性变化实现类百度搜索栏功能ajax异步请求数据,返回字符串
  • 原文地址:https://www.cnblogs.com/csushl/p/11635445.html
Copyright © 2011-2022 走看看