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 ...
随机推荐
- AJPFX关于IO流的简单总结
IO流的分类:1.根据流的数据对象来分:高端流:所有的内存中的流都是高端流,比如:InputStreamReader 低端流:所有的外界设备中的流都是低端流,比如InputStream,Output ...
- "码代码"微信号今日上线,为互联网同仁提供最前沿咨询
"码代码"微信号今日上线 关注即有好礼相送 三月,春意浓浓的日子,三月,属于女人的日子,而今天...... “2014年天空成人放送大赏”于5日晚举办颁奖典礼,“年度最佳AV女优” ...
- 自己编辑Nuget拓展包,并发布Nuget服务器,提供下载使用
1. 在NuGet官网上注册并获取API Key 到NuGet上注册一个新的账号,然后在My Account页面,获取一个API Key,如果没有则在API keys 页面创建一个就可以. 2. 下载 ...
- 查看DNS、IP、Mac等
A.Win98:winipcfg B.Win2000以上:Ipconfig/all C.NSLOOKUP:如查看河北的DNS C:\\>nslookup Default Server: ...
- iView webapp / Mint UI / MUI [前端UI]
前端UI iView webapp一套高质量的 微信小程序 UI 组件库 https://weapp.iviewui.com/?from=iview Mint UI 基于 Vue.js 的移动端组件库 ...
- python根据日期返回星期
import time #定义:timedate为时间戳def formattime(timedate,s="%Y-%m-%d %H:%M:%S"): return ...
- Mysql使用导出导入数据库
要在两台不同的电脑上进行开发,数据库需要统一,由于自己第一次完整的设计表结构,因此多次更改表结构,造成了很多不必要的麻烦, 需要将数据库导出成sql脚本: 命令行下具体用法如下: mysqldump ...
- SQL函数解释(待补)
1.SQL— CONCAT(字符串连接函数) 有的时候,我们有需要将由不同栏位获得的资料串连在一起.每一种资料库都有提供方法来达到这个目的: MySQL: CONCAT() Oracle: CONCA ...
- 「 Luogu P2196 」 挖地雷
# 解题思路 跑 $\text{n}$ 遍 $\text{spfa}$ 并记录路径,找到比当前最长路长的就更新答案,并且将路径也更新,注意起点的处理. # 附上代码 #include <iost ...
- Go:方法
一.基本介绍 在某些情况下,我们需要定义方法.比如 Person 结构体,除了有一些字段外(姓名.年龄...),还可以有一些行为动作(吃.唱歌...),这就需要用方法才能实现. Go中的方法是作用在指 ...