题目:http://codeforces.com/problemset/problem/198/B

Jumping on Walls
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.

The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.

Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:

  • climb one area up;
  • climb one area down;
  • jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.

If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.

The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.

The level is considered completed if the ninja manages to get out of the canyon.

After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly.

The second line contains the description of the left wall — a string with the length of ncharacters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.

The third line describes the right wall in the same format.

It is guaranteed that the first area of the left wall is not dangerous.

Output

Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).

Examples
input

Copy
7 3
---X--X
-X--XX-
output

Copy
YES
input

Copy
6 2
--X-X-
X--XX-
output

Copy
NO
Note

In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.

In the second sample there's no way the ninja can get out of the canyon.

题意:

有一个人在两堵平行的墙之间,每面墙墙被分为n个单位,墙上有一些位置人不能到达,人可以移动,但每次移动水位会上升,人不能碰到水,现在初始位置在左边最下方,就是样例中的左上角,若人当前高度为x,则人每次可以进行三种操作,
第一种是在当前墙上升一个单位即x+1,第二种是在当前墙下降一个单位及x-1,第三种是跳的另一个墙上且高度变为x+k,问人能否跳出墙(人的高度严格大于n!!!注意是严格大于,也就是不能等于)且不被水淹没

思路:

一道非常水的搜索大水题,真想吐槽一下赛时没把问题想明白,在比赛时写成了判断条件写出了y+k>=n,但有可能k==1导致跳了一格后水正好上升一格,就凉凉,赛后改成y+k>n就AC了,真想给当时的自己一巴掌
by the way,注意人物先移动了水才会上升,所以先判断能不能跳出去再判断水有没有上升到人所在的层

注意:

问人能否跳出墙(人的高度严格大于n!!!注意是严格大于,也就是不能等于)且不被水淹没

人物先移动了水才会上升,所以先判断能不能跳出去再判断水有没有上升到人所在的层

 #include<bits/stdc++.h>
using namespace std;
const int amn=1e5+;
#define fi first
#define se second
int n,k,mp[][amn],hm[][amn];bool valid,idx[][amn];
struct pii{
int first,second,h;
pii(int f,int s,int hh){first=f,second=s,h=hh;}
};
void bfs(){
memset(idx,,sizeof idx);
queue<pii> q;
idx[][]=;
q.push(pii(,,));
while(q.size()){
int x=q.front().first,y=q.front().second,h=q.front().h;q.pop();
if(y+k>n){valid=;return;} ///赛时没把问题想明白,在比赛时写成了判断条件写出了y+k>=n,但有可能k==1导致跳了一格后水正好上升一格,就凉凉,赛后改成y+k>n就AC了,真想给当时的自己一巴掌
if(y<=h){continue;} ///这里是先跳了水才会上升,所以先判断能不能跳出去再判断水有没有上升到人所在的层
if(!idx[x][y+]&&mp[x][y+]){idx[x][y+]=;q.push(pii(x,y+,h+));}
if(!idx[x][y-]&&mp[x][y-]){idx[x][y-]=;q.push(pii(x,y-,h+));}
if(!idx[x^][y+k]&&mp[x^][y+k]){idx[x^][y+k]=;q.push(pii(x^,y+k,h+));}
}
}
int main(){
ios::sync_with_stdio();
cin>>n>>k;
char in;
for(int i=;i<=n;i++){
cin>>in;
if(in=='-')mp[][i]=;
else mp[][i]=;
}
for(int i=;i<=n;i++){
cin>>in;
if(in=='-')mp[][i]=;
else mp[][i]=;
}
valid=;
bfs();
if(valid!=)printf("YES\n");
else printf("NO\n");
}
/**
有一个人在两堵平行的墙之间,每面墙墙被分为n个单位,墙上有一些位置人不能到达,人可以移动,但每次移动水位会上升,人不能碰到水,现在初始位置在左边最下方,就是样例中的左上角,若人当前高度为x,则人每次可以进行三种操作,
第一种是在当前墙上升一个单位即x+1,第二种是在当前墙下降一个单位及x-1,第三种是跳的另一个墙上且高度变为x+k,问人能否跳出墙(人的高度严格大于n!!!注意是严格大于,也就是不能等于)且不被水淹没
一道非常水的搜索大水题,真想吐槽一下赛时没把问题想明白,在比赛时写成了判断条件写出了y+k>=n,但有可能k==1导致跳了一格后水正好上升一格,就凉凉,赛后改成y+k>n就AC了,真想给当时的自己一巴掌
by the way,注意人物先移动了水才会上升,所以先判断能不能跳出去再判断水有没有上升到人所在的层
**/

[BFS,大水题] Codeforces 198B Jumping on Walls的更多相关文章

  1. Jumping on Walls CodeForces - 198B

    Jumping on Walls CodeForces - 198B 应该是一个隐式图的bfs,或者叫dp. 先是一个TLE的O(nklogn) #include<cstdio> #inc ...

  2. BZOJ_1621_[Usaco2008_Open]_Roads_Around_The_Farm_分岔路口(模拟+大水题)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1621\(n\)头奶牛,刚开始在一起,每次分成\(x\)和\(x+m\)两部分,直到不能再分,问 ...

  3. 第三届山西省赛1004 一道大水题(scanf)

    一道大水题 时间限制: C/C++ 2000ms; Java 4000ms 内存限制: 65535KB 通过次数: 44 总提交次数: 1020 问题描述 Dr. Pan作为上兰帝国ACM的总负责人, ...

  4. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  5. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

  6. PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)

    如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...

  7. BFS简单题套路_Codevs 1215 迷宫

    BFS 简单题套路 1. 遇到迷宫之类的简单题,有什么行走方向的,先写下面的 声明 ; struct Status { int r, c; Status(, ) : r(r), c(c) {} // ...

  8. POJ-2251 Dungeon Master (BFS模板题)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  9. 【数据结构】 最小生成树(四)——利用kruskal算法搞定例题×3+变形+一道大水题

    在这一专辑(最小生成树)中的上一期讲到了prim算法,但是prim算法比较难懂,为了避免看不懂,就先用kruskal算法写题吧,下面将会将三道例题,加一道变形,以及一道大水题,水到不用高级数据结构,建 ...

随机推荐

  1. seaJs模块化开发简单入门

    随着前端技术的日益成熟,功能越来越丰富强大,规范也越来越健全,在这样的背景环境下很快便有了CommonJs.AMD.CMD等一系列规范,使前端发开趋向模块化.规范化.CMD模块化的代表之一就是国内开发 ...

  2. 关于RN的热更新

    写点关于RN的热更新和RN版本升级后的强制更新.以及优化白屏问题 在APPDelegate中加载RN,一般的加载方式是:RCTRootView *rootView= [[RCTRootView all ...

  3. C:指针习题

    1. 请指出以下程序段中的错误. 程序中的错误有:(1)p=i:类型不匹配.(2)q=*p:q 是指针,*p 是指针 p 指向变量的值.(3)t='b':t 是指针类型. 解释:指针变量是一种存放地址 ...

  4. iMX287A多种方法实现流水灯效果

    目录 1.流水灯在电子电路中的地位 2.硬件电路分析 3.先点个灯吧 4.shell脚本实现流水灯 5.ANSI C文件操作实现流水灯 6.Linux 系统调用实现流水灯 @ 1.流水灯在电子电路中的 ...

  5. App崩溃监控

    常见马虎导致崩溃 1 数组越界: 2 多线程问题,在子线程刷新UI: 3 主线程无响应,主线程超过系统规定的时间没有响应,就会被watchdog杀掉: 4 野指针: 崩溃信息的收集却并没有那么简单.因 ...

  6. html/css系列-图片上下居中

    本文详情:http://www.zymseo.com/276.html图片上下居中的问题常用的几种方法:图片已知大小和未知大小,自行理解 .main{ width: 400px;height: 400 ...

  7. 一键制作镜像并发布到k8s

    *:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...

  8. java线程间的共享

    本次内容主要讲synchronized.volatile和ThreadLocal. 1.synchronized内置锁 线程开始运行,拥有自己的栈空间,就如同一个脚本一样,按照既定的代码一步一步地执行 ...

  9. url,href和src的区别,defer和async的区别

    URL(Uniform Resource Locator):统一资源定位符,互联网上的每个文件都有一个唯一的URL,基本URL包含协议,IP地址,路径和文件名. 重点:herf和src的区别 href ...

  10. 使用java短信验证

    package cn.geekss.util; import java.io.BufferedReader;import java.io.InputStreamReader;import java.i ...