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 ...
随机推荐
- c# byte转docx
问题情境: docx文件放进resource中,再用程序读出来的时候是二进制数组. 解决办法: public string ByteConvertWord(byte[] data, string fi ...
- Educational Codeforces Round 16 E. Generate a String dp
题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...
- 初识 es6之 const
const声明一个只读的常量.一旦声明,常量的值就不能改变. 例子: const a=12; a=2;//报错,const 声明的是常量,不能改 const声明的变量不得改变值,这意味着,const一 ...
- 【Linux】- 六个超赞的字符画生成器
ASCII是一个非常吸引人的字符编码系统,在计算机,通讯设备,以及其他设备中,通过它来用代码表示字符.新生代的人可能会觉得它已经过时了,但是那些熟悉它的人会懂得ASCII是多么的独特.我们在这里为你准 ...
- ubuntu 手动apache记录
1.下载apache tar -xvzf httpd.xx 解压 2.下载安装pcre Download PCRE from PCRE.org 解压,进入文件夹中 ./configure --pre ...
- Linux下objdump查看C程序编译后的汇编代码
http://m.blog.csdn.net/article/details?id=47747047 Uboot中start.S源码的指令级的详尽解析 http://www.crifan.com/fi ...
- Web模块:spring-boot-starter-web
spring-boot-autoconfigure-1.5.1.RELEASE.jar!/org/springframework/boot/autoconfigure/web 上述jar的web包下, ...
- list的迭代器能解决并发问题,collection 的迭代器不能解决并发问题,for可以解决并发问题
list的迭代器能解决并发问题,collection 的迭代器不能解决并发问题 为什么list支持add,collection不支持 例如有两个人同时添加第三个元素 list的迭代器能锁定线程 只有等 ...
- 转:python的nltk中文使用和学习资料汇总帮你入门提高
python的nltk中文使用和学习资料汇总帮你入门提高 转:http://blog.csdn.net/huyoo/article/details/12188573 nltk的安装 nltk初步使用入 ...
- Jsp遍历后台传过来的List
1:使用jstl标签 (可以和自定义标签配合使用) 首先引用jstl标签 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" ...