题目描述

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

提示

The objective is achievable by, for example, moving the two persons as follows. (A and B represent Snuke and Fnuke, respectively.)

A#B.#..
A#.B#..
.#AB#..
.#A.#B.
.#.A#B.
.#.A#.B
.#..#AB


【题解】:
题目没有给定A,C与B,D之间的关系,所以我们分类讨论,
如果C==D,则无解,
如果两个区间不重叠,那么我们只要单独判断每一个区间内是否合法。
如果两个区间是相交的,那么我们需要判断一下中间是否有三个空位让A跳过去。先判断B是否能到D,如果不能,则无解,如果可以,还需要在路途中A,C路上是否有三个阻碍物,不然无法跳出去。

 1 #include<bits/stdc++.h>
 2 using namespace std ;
 3 const int N = 2e5+100;
 4 char s[N];
 5 int main (){
 6     int n,A,B,C,D;
 7     scanf("%d%d%d%d%d",&n,&A,&B,&C,&D);
 8     scanf("%s",s+1);
 9     if( C == D ){
10         printf("No\n");
11     }else if( C < D ){
12         int flag = 1 ;
13         // if( s[C] == '#' || s[D] == '#' ) flag = 0 ;
14         for ( int i = A ; i < C ; i++ ){
15             if ( s[i] == '#' && s[i+1] == '#' ){
16                 flag = 0;
17                 break ;
18             }
19         }
20         for ( int i = B ; i < D ; i++ ){
21             if ( s[i] == '#' && s[i+1] == '#' ){
22                 flag = 0;
23                 break ;
24             }
25         }
26         if( flag ){
27             printf("Yes\n");
28         }else{
29             printf("No\n");
30         }
31     }else{
32         int flag = 1 ;
33         for ( int i = B ; i < D ; i++ ){
34             if ( s[i] == '#' && s[i+1] == '#' ){
35                 flag = 0;
36                 break ;
37             }
38         }
39         for ( int i = A ; i < C ; i++ ){
40             if (
41             (s[i] == '#' && s[i+1] == '#') ||
42             (s[i] == '#' && i+1 == D ) ||
43             (s[i+1] == '#' && i == D )
44             ){
45                 flag = 0;
46                 break ;
47             }
48         }
49
50         int f = 0 ;
51         for ( int i = B  ; i <= D-1 ; i++ ){
52             if ( s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' ){
53                 f = 1 ;
54                 break;
55             }
56         }
57         if( flag || f ){
58             printf("Yes\n");
59         }else{
60             printf("No\n");
61         }
62     }
63     return 0 ;
64 }

Kenken Race

转载于:https://www.cnblogs.com/Osea/p/11211252.html

【思维】Kenken Race相关推荐

  1. Kenken Race

    Kenken Race 题目描述: There are N squares arranged in a row, numbered 1,2,-,N from left to right. You ar ...

  2. 【AtCoder】AGC034

    AGC034 刷了那么久AtCoder我发现自己还是只会ABCE(手动再见 A - Kenken Race 大意是一个横列,每个点可以跳一步或者跳两步,每个格子是空地或者石头,要求每一步不能走到石头或 ...

  3. 超干货!当初我要是这么学习操作系统就好了(附带思维导图)

    点击蓝色"小詹学Python"关注我哟 加个"星标",一起走向人生巅峰! 1 下面是本文的思维导图 我们平常说的进程和线程更多的是基于编程语言的角度来说的,那么 ...

  4. 001 计算思维-卡内基梅隆大学计算机系主任周以真(英汉对照版)

    英文版CACM Jeannette M. Wing (周以真) (翻译:徐韵文,王飞跃, 校对:王飞跃) Computational Thinking It represents a universa ...

  5. 整理总结:利用Python进行数据分析及思维导图

    参考资料:机械工业出版社的<利用Python进行数据分析>(思维导图在最后面) 本篇目录 参考资料:机械工业出版社的<利用Python进行数据分析>(思维导图在最后面) 第一章 ...

  6. 17张思维导图,2021年作为一名前端开发者需要掌握这些,前端面试复习资料参考大纲

    本文首发于17张思维导图,2021年作为一名前端开发者需要掌握这些,前端面试复习资料参考大纲,转载请联系作者 前言 2020年最后一个月了,熬夜多天整理出17张思维导图,对前端面试复习知识点进行了最全 ...

  7. java race condition_java 多线程下race condition问题

    这个问题的讨论来自内部的一个关于"多线程环境下使用Hashmap的安全问题"的讨论,HashMap多线程的问题之前已经提过一次,见之前的blog.本篇文章主要讨论多线程下race ...

  8. 当初我要是这么学习「进程和线程」就好了(附带思维导图)

    作者 | cxuan 来源 | Java建设者 本文思维导图 我们平常说的进程和线程更多的是基于编程语言的角度来说的,那么你真的了解什么是线程和进程吗?那么我们就从操作系统的角度来了解一下什么是进程和 ...

  9. 揭富人与穷人21个不同思维 看富豪如何脱颖而出

    <富人是怎么想的>(How Rich People Think)的作者Steve Siebold曾在近30年里采访世界各地的富豪,看究竟是什么让富豪从普通人中站出来. 他发现这和金钱基本没 ...

最新文章

  1. WMI技术介绍和应用——查询磁盘分区和逻辑磁盘信息
  2. 程序猿接私活经验总结,来自csdn论坛语录
  3. 三菱gx软件初始化失败怎么解决_三菱PLC的常见问题大全!
  4. java生成pdf_Java实现PDF文件生成并且打印pdf文件 demo
  5. 【转】ABP源码分析二十:ApplicationService
  6. 耳目一新的在线答疑服务背后的核心技术
  7. springBoot跨域解决
  8. 面试官:说一下JVM常用垃圾回收器的特点、优劣势、使用场景和参数设置
  9. 感觉自己应该重新读一次Javascript
  10. 最优矩阵链乘(动态规划)
  11. linux删除用户名命令,linux删除用户命令
  12. 仿真软件都在这里了!20+国内外自动驾驶仿真软件大盘点
  13. 世界头号黑客米特尼克自传
  14. android 转盘菜单,Android实现可点击的幸运大转盘
  15. LED 发光二极管压降
  16. 动态规划算法典型应用之背包问题
  17. android手机电视助手是如何控制电视的呢?
  18. Android Remote Views
  19. Matplotlib 中文用户指南 4.8 XeLaTeX/LuaLaTeX 设置
  20. Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/

热门文章

  1. linux-gcc 编译时头文件和库文件搜索路径
  2. [轉]Windows下Subversion配置管理员指南
  3. PowerShell2.0之与COM对象交互(五)与脚本宿主代码协同工作
  4. Apache 服务器的安全策略
  5. ARCGIS 拓扑规则阐述
  6. 问题 K: 数字统计
  7. ajax响应码,jQuery 使用$ .ajax()处理HTTP响应代码
  8. 系统相机裁剪比例_从照相到摄影你只差这5个技巧!人像裁剪这4大原则你一定要了解...
  9. mysql联合索失效_mysql 联合索引生效的条件、索引失效的条件
  10. asp/php招聘,招聘ASP与PHP相关岗位的笔经