题目: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. rsync auth failed on module xxx

    rsync 报错 "auth failed on module xxx", 一般有三种情况造成: 密码文件格式错误: 服务端密码文件的格式是: user:password 每个一行 ...

  2. python常用魔术方法概览

    构造和初始化 __init__(self, args) 构造函数 __new__(cls) 传入的是类实例 __del__(self) 析构函数,调用 del cls 时会被调用 属性访问控制 __g ...

  3. 简单的员工管理系统(Mysql+jdbc+Servlet+JSP)

    员工管理系统 因为学业要求,需要完成一个过关检测,但是因为检测之前没有做好准备,且想到之前用mysql+jdbc+Struts2+bootstrap做成了一个ATM系统(主要有对数据的增删改查操作), ...

  4. springboot框架中集成thymeleaf引擎,使用form表单提交数据,debug结果后台获取不到数据

    springboot框架中集成thymeleaf引擎,使用form表单提交数据,debug结果后台获取不到数据 表单html: <form class="form-horizontal ...

  5. 聊一聊MyBatis 和 SQL 注入间的恩恩怨怨

    整理了一些Java方面的架构.面试资料(微服务.集群.分布式.中间件等),有需要的小伙伴可以关注公众号[程序员内点事],无套路自行领取 更多优选 一口气说出 9种 分布式ID生成方式,面试官有点懵了 ...

  6. JDBC大数据的采取

    ## JDBC的大类型数据的存取 ## # 基本概念: |-- 大文本类型数据和大二进制数据: 主要思想用于将大型的二进制数据(字节) 或是大型的文本数据(字符)从磁盘文件中读取 到数据库中,或是从数 ...

  7. leetcode 1365. How Many Numbers Are Smaller Than the Current Number

    Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. T ...

  8. Arthas 实战,助你解决同名类依赖冲突问题

    上篇文章中,小黑哥分析 Maven 依赖冲突分为两类: 项目同一依赖应用,存在多版本,每个版本同一个类,可能存在差异. 项目不同依赖应用,存在包名,类名完全一样的类. 第二种情况,往往是这个场景,本地 ...

  9. How to solve the problem that Github can't visit in China?

    find path C:\Windows\System32\drivers\etc\host open DNS detection and DNS query-Webmaster(DNS查询) too ...

  10. 初识 jquery.simulate.js 模拟键盘事件

    用jquery 和 jquery.simulate.js 实现模拟键盘事件,点击上下左右div相当于点击键盘的上下左右键 <!DOCTYPE html> <html> < ...