Contest1786 - 2019年第二阶段我要变强个人训练赛第十场 A: Kenken Race(思维)

时间限制: 1 Sec  内存限制: 128 MB
提交: 226  解决: 37
[提交] [状态] [命题人:admin]

题目描述

There are N squares arranged in a row, numbered 1,2,...,N from left to right. You are given a string S of length N consisting of . and #. If the i-th character of S is #, Square i contains a rock; if the i-th character of S is ., Square i is empty.
In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.
You can repeat the following operation any number of times:
Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.
You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.
Determine whether this is possible.

Constraints
4≤N≤200000
S is a string of length N consisting of . and #.
1≤A,B,C,D≤N
Square A, B, C and D do not contain a rock.
A, B, C and D are all different.
A<B
A<C
B<D

 

输入

Input is given from Standard Input in the following format:

N A B C D
S

 

 

输出

Print Yes if the objective is achievable, and No if it is not.

 

样例输入

7 1 3 6 7
.#..#..

样例输出

Yes

 

分情况讨论,题目没有指明C和D的关系,现在我们分类讨论。

1.C==D:肯定是“No”。

2.C<D:可以先让B到D,再让A到C。所以直接判断B能否到D,A能否到C即可。

3.C>D:先判断一下B能否到D,如果不能的话肯定是“No”;否则,这种情况下可能出现在A向C走的时候,被B挡住。我们可以先把B放在D的位置上,如果A能走到C,那么就是“Yes”;否则,也就是说B在某一时刻挡住了A的去路,解决的方法就是在[B-1,D]之间有连续的3个空位,那么就可以利用这3个空位过渡。有就是“Yes”,没有就是“No”。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+10;
char s[N];
int main(void)
{
    int n,a,b,c,d;
    bool flag1=0,flag2=0; 
    scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s+1);
    if(c==d)
    {
        printf("No\n");
        return 0;
    }
    //A能否到C 
    for(int i=a;i<c;i++)
    {
        if(s[i]=='#'&&s[i+1]=='#')
        {
            flag1=1;
            break;
        }
    }
    //B能否到D 
    for(int i=b;i<d;i++)
    {
        if(s[i]=='#'&&s[i+1]=='#')
        {
            flag2=1;
            break;
        }
    }
    if(c<d)
    {
        if(flag1||flag2)
            printf("No\n");
        else
            printf("Yes\n");
        return 0;       
    }
    else
    {
    	//B不能到D 
        if(flag2)
        {
            printf("No\n");
            return 0;   
        } 
        bool flag3=1;
        //B在D的位置上,A能否到C   
        for(int i=a;i<c;i++)
        {
            if((s[i]=='#'&&s[i+1]=='#')||(s[i]=='#'&&i+1==d)||(i+1<=c&&i==d&&s[i+1]=='#'))
            {
                flag3=0;
                break;
            }
        }
        if(flag3)   
        {
            printf("Yes\n") ;
            return 0;
        }     
         //是否有3个空位  
        bool flag4=0;
        for(int i=b-1;i+2<=d;i++)    
        {
            if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')
                flag4=1;
        }
        if(flag4)
            printf("Yes\n");
        else printf("No\n");
    }
    return 0;   
} 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值