Ice Cave-CodeForces(广搜)
链接:http://codeforces.com/problemset/problem/540/C
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).
You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.
Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
If you can reach the destination, print 'YES', otherwise print 'NO'.
4 6
X...XX
...XX.
.X..X.
......
1 6
2 2
YES
5 4
.X..
...X
X.X.
....
.XX.
5 3
1 1
NO
4 7
..X.XX.
.XX..X.
X...X..
X......
2 2
1 6
YES
In the first sample test one possible path is:

After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
题目大意:
给你一个二维的图形 ‘X’表示碎冰 ‘.'便是完整的冰下面简称好冰
好冰走过一次会变成碎冰 碎冰走过一次破了 毁掉下去
现在给你起点和终点 然后看是否能从起点走到终点然后再终点掉下去。
分析:
典型的搜索
但是就是判断条件难了点,,我写的时候调试了好长时间终于A了
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std; #define INF 0xfffffff
#define N 700
int d[][]={{,},{-,},{,},{,-}};
int vis[N][N];
char maps[N][N];
struct node
{
int x,y;
}s,e,p; int bfs(int n,int m)
{
queue<node>Q;
Q.push(s);
memset(vis,,sizeof(vis));
vis[s.x][s.y]=;
while(!Q.empty())
{
node u,v;
u=Q.front();
Q.pop(); for(int i=;i<;i++)
{
v.x=u.x+d[i][];
v.y=u.y+d[i][];
if(maps[v.x][v.y]=='X' && v.x==e.x && v.y==e.y)
return ;
if(maps[v.x][v.y]=='.' && v.x>= && v.y>= && v.x<n && v.y<m && !vis[v.x][v.y])
{
Q.push(v);
vis[v.x][v.y]=;
maps[v.x][v.y]='X';
}
}
}
return ;
} int main()
{
int n,m,i,s1,e1,s2,e2;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(maps,,sizeof(maps));
for(i=;i<n;i++)
{
scanf("%s",maps[i]);
}
scanf("%d %d %d %d",&s1,&e1,&s2,&e2);
s.x=s1-;
s.y=e1-;
e.x=s2-;
e.y=e2-;
if(bfs(n,m)==)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
Ice Cave-CodeForces(广搜)的更多相关文章
- (简单广搜) Ice Cave -- codeforces -- 540C
http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- 『ice 离散化广搜』
ice(USACO) Description Bessie 在一个冰封的湖面上游泳,湖面可以表示为二维的平面,坐标范围是-1,000,000,000..1,000,000,000. 湖面上的N(1 & ...
- CodeForces 540C Ice Cave (BFS)
http://codeforces.com/problemset/problem/540/C Ice Cave Time Limit:2000MS Memory Limit:262 ...
- Codeforces Round #301 (Div. 2) C. Ice Cave BFS
C. Ice Cave Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/problem/C ...
- CodeForces 682C Alyona and the Tree(广搜 + 技巧)
方法:从根节点开始广搜,如果遇到了应该删除的点,就再广搜删掉它的子树并标记,然后统计一下被标记的个数就是答案,所谓技巧就是从根节点开始搜索的时候,如果遇到了某个节点的距离<0,就让它是0,0可以 ...
- CodeForces - 540C Ice Cave —— BFS
题目链接:https://vjudge.net/contest/226823#problem/C You play a computer game. Your character stands on ...
- Codeforces 1105D(双层广搜)
要点 题意:可以拐弯,即哈密顿距离 注意不可以直接一个一个搜,这过程中会把下一轮的标记上,导致同一轮的其它点没能正常完成应有的搜索 因此采用双层广搜,把同一轮先都出队列再的一起搜 #include & ...
- CF520B——Two Buttons——————【广搜或找规律】
J - Two Buttons Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
随机推荐
- java课程设计全程实录——第1天
反思,总结昨天: IDE搭建完成: git远程配置失败,处理方式:放弃使用git 主要参考<疯狂java实战演义>中的图书进销存管理系统.但该项目是MySQL,无法直接套用,因为我们学的是 ...
- jquery js 分页
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title>jQuery.pager ...
- oracle 代码块
oracle 的代码块模板 declare --声明变量 begin --执行业务逻辑 exception --异常处理 end; --结束 注意:代码块每个sql语句结束都要加冒号 eg: --pl ...
- [Windows Server 2012] 阿里云镜像购买和使用方法
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将演示:阿里云镜像购买 ...
- zabbix企业应用之windows系统安装omsa硬件监控
具体请参考 作者:dl528888http://dl528888.blog.51cto.com/2382721/1421335 大致 1.安装OMSA http://zh.community.de ...
- mac webstrom 安装less
1.检验电脑是否安装less lessc -v 2.如果没有执行全局安装命令 npm install -g less 3.webstrom -> Preferencs-> File Wat ...
- 迅为IMX6UL工业级商业扩展级核心板兼容同一底板
商业级IMX6UL核心板: ARM Cortex-A7架构 主频高达528 MHz 核心板512M DDR内存 8G EMMC 存储 运行温度:-20℃ ~ +80℃ CPU集成电源管理 核心板尺寸仅 ...
- mysql 查看存储过程 并导出
查询数据库中的存储过程 select * from mysql.proc where db = dbName and `type` = 'PROCEDURE' show procedure statu ...
- idea文件全部变红, 文件全部红色
idea如果当前project用了版本控制器,其下面新建的所有的项目默认都是加入到版本控制里面,所以项目名称和文件都是红色的,如图: 看起来非常不爽, 那么如何解决呢? File–>Settin ...
- ORA-39126: Worker unexpected fatal error in KUPW$WORKER.PUT_DDLS
末尾加上EXCLUDE=STATISTICS /home/opt/oracle/11g/bin/expdp user/password directory=backup2 network_link=d ...