CF540 C BFS 水
'.'->'X'
前者走后变成后者,后者除了是终点不能再走。初始位置是X很傻的以为这样从初始点走出去后初始位置就变成不能走了,实际上是还能走一次的。
其他就是BFS,路上记得把路变成X就好了
太傻了,特记一下
/** @Date : 2017-08-27 19:38:53
* @FileName: C BFS.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int n, m;
char mp[600][600];
int vis[600][600];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int sx, sy, tx, ty; int bfs(int sx, int sy, int tx, int ty)
{
queue<PII >q;
q.push(MP(sx, sy));
//vis[sx][sy] = 2;//题目自己说起始点是X了 那么不是不能再走了么?怎么又变成说是走完后是X了
while(!q.empty())
{
PII nw = q.front();
q.pop(); for(int i = 0; i < 4; i++)
{
int nx = nw.fi + dir[i][0];
int ny = nw.se + dir[i][1];
if(nx == tx && ny == ty && vis[tx][ty] == 1)
return 1;
if(!vis[nx][ny] && nx > 0 && ny > 0 && nx <= n && ny <= m)
{
q.push(MP(nx, ny));
vis[nx][ny]++;
}
}
}
return 0;
}
int main()
{
while(cin >> n >> m)
{
MMF(vis);
for(int i = 1; i <= n; i++)
{
scanf("%s", &mp[i][1]);
for(int j = 1; j <= m; j++)
if(mp[i][j] == 'X')
vis[i][j] = 1;
}
scanf("%d%d", &sx, &sy);
scanf("%d%d", &tx, &ty);
int ans = bfs(sx, sy, tx, ty);
printf("%s\n", ans?"YES":"NO");
}
return 0;
}
CF540 C BFS 水的更多相关文章
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- hdu1240 bfs 水题
原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...
- nyoj--523--亡命逃窜(BFS水题)
亡命逃窜 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 从前有个叫hck的骑士,为了救我们美丽的公主,潜入魔王的老巢,够英雄吧.不过英雄不是这么好当的.这个可怜的娃被魔 ...
- POJ 3669 Meteor Shower BFS 水~
http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...
- [Usaco2007 Dec]穿越泥地[bfs][水]
Description 清早6:00,Farmer John就离开了他的屋子,开始了他的例行工作:为贝茜挤奶.前一天晚上,整个农场刚经受过一场瓢泼大雨的洗礼,于是不难想见,FJ 现在面对的是一大片泥泞 ...
- POJ3287(BFS水题)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- POJ 3126 Prime Path bfs, 水题 难度:0
题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...
- POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)
http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...
- hdu - 2645 find the nearest station (bfs水)
http://acm.hdu.edu.cn/showproblem.php?pid=2645 找出每个点到距离最近的车站的距离. 直接bfs就好. #include <cstdio> #i ...
随机推荐
- Thunder团队——选题展示
团队名称:Thunder 组长:王航 成员:李传康.代秋彤.邹双黛.苗威.宋雨.胡佑蓉.杨梓瑞 项目名称:爱阅app 视频展示: http://www.cnblogs.com/lick468/p/76 ...
- 团队目标WBS及具体任务分工
• 首先我们讨论了实验第一个冲刺周期要实现的功能,我们的初期目标. • 然后我们进一步梳理了第一阶段的任务和需求. • 之后对任务进行了划分和领取. • 最后每个人对自己的任务进行了估算,并约定 ...
- sql主表分页查询关联子表取任意一条高效方案
有个业务场景,主表中一条数据,在子表中有多条详情数据.对数据进行展示的时候,产品希望随意拿一条子表的数据关联展示出来,用了很多方案,但是都不够好. sql查询取子表任意一条,多个字段的方案 最终找到一 ...
- c语言基础笔记
一 :数据类型 1.float类型,在输出的时候可以使用 .数字 来把浮点数精确到小数点后几位,比如 printf("%.3f",float)精确到小数点后三位,不足补0 2.字 ...
- SQL的拼接语句在DELPHI中怎么写
SQL 语句的拼接,关键点在于对引号的处理上. 在 delphi 的语法中,使用单引号做字符串的标志符.因此,当遇到 SQL 语句中字符串标识量编写的时候,需要用两个单引号来代替实际的引号. 举例: ...
- SpringMVC Ajax两种传参方式
1.采用@RequestParam或Request对象获取参数的方法 注:contentType必须指定为:application/x-www-form-urlencoded @ResponseBod ...
- echarts tooltip 自定义formatter怎么设置颜色?
formatter: function(params) { var result = ''; params.forEach(function (item) { result += item.marke ...
- web端调百度地图页面
在点击进入地图的入口(下面数据是vue渲染的数据) <a class="navigation" v-if="merchant.longitude && ...
- SpingCloud之feign框架调用
1.生产者(没有什么特殊性) pom.xml <?xml version="1.0" encoding="UTF-8"?> <project ...
- BZOJ 1189 紧急疏散(二分+最大流)
求出所有人撤离的最短时间.由于每扇门只能通过一次,所以不能简单用bfs来搞. 显然答案是有单调性的,考虑二分,问题变成了判断时间x所有人能不能撤离. 考虑最大流.对于每扇门,每个时间通过的人数最多为1 ...