题目描述

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.

样例输入

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

样例输出

  1. 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+;
  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+);
  9. if( C == D ){
  10. printf("No\n");
  11. }else if( C < D ){
  12. int flag = ;
  13. // if( s[C] == '#' || s[D] == '#' ) flag = 0 ;
  14. for ( int i = A ; i < C ; i++ ){
  15. if ( s[i] == '#' && s[i+] == '#' ){
  16. flag = ;
  17. break ;
  18. }
  19. }
  20. for ( int i = B ; i < D ; i++ ){
  21. if ( s[i] == '#' && s[i+] == '#' ){
  22. flag = ;
  23. break ;
  24. }
  25. }
  26. if( flag ){
  27. printf("Yes\n");
  28. }else{
  29. printf("No\n");
  30. }
  31. }else{
  32. int flag = ;
  33. for ( int i = B ; i < D ; i++ ){
  34. if ( s[i] == '#' && s[i+] == '#' ){
  35. flag = ;
  36. break ;
  37. }
  38. }
  39. for ( int i = A ; i < C ; i++ ){
  40. if (
  41. (s[i] == '#' && s[i+] == '#') ||
  42. (s[i] == '#' && i+ == D ) ||
  43. (s[i+] == '#' && i == D )
  44. ){
  45. flag = ;
  46. break ;
  47. }
  48. }
  49.  
  50. int f = ;
  51. for ( int i = B ; i <= D- ; i++ ){
  52. if ( s[i-] == '.' && s[i] == '.' && s[i+] == '.' ){
  53. f = ;
  54. break;
  55. }
  56. }
  57. if( flag || f ){
  58. printf("Yes\n");
  59. }else{
  60. printf("No\n");
  61. }
  62. }
  63. return ;
  64. }

Kenken Race

【思维】Kenken Race的更多相关文章

  1. 【AtCoder】AGC034

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

  2. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  3. Photoshop、Illustrator思维导图笔记

    半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.

  4. CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维

    前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...

  5. 计算机程序的思维逻辑 (8) - char的真正含义

    看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...

  6. 计算机程序的思维逻辑 (29) - 剖析String

    上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...

  7. 计算机程序的思维逻辑 (31) - 剖析Arrays

    数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...

  8. 计算机程序的思维逻辑 (33) - Joda-Time

    Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...

  9. 计算机程序的思维逻辑 (53) - 剖析Collections - 算法

    之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...

随机推荐

  1. OpenGL+VS2010环境配置及遇到的问题

    OpenGL+VS2010+GLUT工具包+WIN10系统: 第一步,安装GLUT工具包 Windows环境下的GLUT下载地址:(大小约为150k) http://www.opengl.org/re ...

  2. CF1214B

    CF1214B 解法: 暴力枚举,时间复杂度 $ O(n) $ CODE: #include<iostream> #include<cstdio> #include<cs ...

  3. 解析配置文件 redis.conf

    1.units单位 2.INCLUDES包含 3.GENERAL通用 1).daemonize daemonize yes 启用后台守护进程运行模式 2).pidfile pidfile /var/r ...

  4. linux里面源码安装imagemagick库

    在搞树莓派的时候想搞一下树莓派中摄像头获取图像之后传给安卓,安卓进行展示. 恰好用到了imagemagick这个库,我就像正常一样进行安装,sudo apt-get install Imagick 但 ...

  5. kotlin 类的委托

    fun main(arg: Array<String>) { val baseImpl = baseImpl() demo(baseImpl).printL() } interface b ...

  6. HttpServletRequest&HttpServletResponse对象

    HttpServletRequest&HttpServletResponse对象不是由我们来创建的,而是由tomcat服务器创建,那么我们就可以直接来使用这两个 对象 A: HttpServl ...

  7. android设置gps自动开启

    1.第一种方法 private void toggleGPS() { Intent gpsIntent = new Intent(); gpsIntent.setClassName("com ...

  8. 003-多线程-JUC集合-Set-CopyOnWriteArrayList

    一.概述 它是线程安全的无序的集合,可以将它理解成线程安全的HashSet.有意思的是,CopyOnWriteArraySet和HashSet虽然都继承于共同的父类AbstractSet:但是,Has ...

  9. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_21-页面静态化-静态化测试-静态化程序编写

    public String getPageHtml(String pageId){ /** * 静态化程序获取页面的DataUrl * * 静态化程序远程请求DataUrl获取数据模型 * * 静态化 ...

  10. Java中遍历Map的四种方式

    Demo如下 Map<String, String> map = new HashMap<>(); map.put("key1","data1&q ...