题目: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. 两篇很好的EPG相关文章

    两篇很好的EPG相关文章 原文地址:http://blog.sina.com.cn/s/blog_53220cef0100pi8j.html 1 基于DVB-SI的数字有线电视机顶盒节目指南的设计实现 ...

  2. 亚马逊,谷歌,Facebook,IBM和微软:为了AI,是的,我们在一起了

    美国时间9月28日,也就是几个小时前,亚马逊,谷歌,Facebook,IBM和微软宣布成立了一家非盈利组织:人工智能合作组织(Partnership on AI),目标是为人工智能的研究制定和提供范例 ...

  3. LeetCode~1033.移动石子直到连续

    1033.移动石子直到连续 三枚石子放置在数轴上,位置分别为 a,b,c. 每一回合,我们假设这三枚石子当前分别位于位置 x, y, z 且 x < y < z.从位置 x 或者是位置 z ...

  4. LeetCode 31:递归、回溯、八皇后、全排列一篇文章全讲清楚

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天我们讲的是LeetCode的31题,这是一道非常经典的问题,经常会在面试当中遇到.在今天的文章当中除了关于题目的分析和解答之外,我们还会 ...

  5. AOP面试知识整理,^_^-包括spring Aop

    讲到java企业级开发框架,就不可避免的讲到 IOC,AOP,MCV 今天面试时被问到AOP,讲的很乱,这里整理笔记,包括AOP,spring-AOP的部分知识,错误的地方请小伙伴指出来. 谈谈你对A ...

  6. removeAttribute getAttribute setAttribute

    1.removeAttribute() 方法删除指定的属性. 注:removeAttributeNode() 方法从元素中删除指定的属性节点.简单的来讲,removeAttribute() 移除元素内 ...

  7. HTTP入门(一):在Bash中curl查看请求与响应

    HTTP入门(一):在Bash中curl查看请求与响应 本文简单总结HTTP的请求与响应. 本文主要目的是对学习内容进行总结以及方便日后查阅. 详细教程和原理可以参考HTTP文档(MDN). 本文版权 ...

  8. LeetCode 154.Find Minimum in Rotated Sorted Array II(H)(P)

    题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ( ...

  9. 基础JavaScript练习(三)总结

    任务目的 实践JavaScript数组.字符串相关操作 任务描述 基于任务四进行升级 将新元素输入框从input改为textarea 允许一次批量输入多个内容,格式可以为数字.中文.英文等,可以通过用 ...

  10. JZOJ 5257. 小X的佛光 (Standard IO)

    5257. 小X的佛光 (Standard IO) Time Limits: 2000 ms Memory Limits: 524288 KB Description Input Output Sam ...