bnu 52037 Escape from Ayutthaya
Escape from Ayutthaya
This problem will be judged on CodeForcesGym. Original ID: 101047E
64-bit integer IO format: %I64d Java class name: (Any)
Input/Output: standard input/output
Ayutthaya was one of the first kingdoms in Thailand, spanning since its foundation in 1350 to its collapse in 1767. The organization of Extraordinary Mystery Investigators (IME, in their language) aims to uncover the secrets of this ancient kingdom. One of IME's most notorious historians is Márcio "the indispensable" Himura. He is currently researching the laws and punishments in place during King Ramathibodi I's rule. Recent discoveries suggest how Ramathibodi I used to punish the subjects that did not convert to Theravada Buddhism, the religion he adopted.
The punishment involved trapping the accused prisoner in a room with a single exit and to light up a fire. If the prisoner could manage to reach the exit before getting caught on fire, she or he was forgiven and allowed to live. Márcio has access to some records that describe the floorplans of the rooms where this punishment took place. However, there are no documents asserting whether the prisoners were forgiven. Márcio would like to know whether each of these prisoners had any chance at all of having been forgiven. For that, Márcio represented each room as a grid with N rows and M columns, where each position has a symbol with the following meaning

where "start" is the person's initial position in the room when fire has been lit up. Moreover, Márcio imposed the following constraints in his model:
- Fire spreads in the four cardinal directions (N, S, E, O) at the speed of one cell per minute.
- The prisoners can also move in these four directions at the same speed.
- Neither fire nor the prisoners can walk through a wall.
- If the prisoner and fire occupy the same position at any instant, the prisoner dies instantaneously.
You are a member of IME and Márcio would like to know if you deserve your position. He has charged you with the task of determining whether a prisoner had any chance to be forgiven.
Input
The first line has a single integer T, the number if test cases.
Each instance consists of several lines. The first line contains two integers, N and M. Each of the following N lines contains exactly M symbols representing, as described above, a room from which the prisoner must escape.
Limits
- 1 ≤ T ≤ 100
- The sum of the sizes of the matrices in all test cases will not exceed 2 cdot106
- 1 ≤ N ≤ 103
- 1 ≤ M ≤ 103
Output
For each instance, print a single line containing a single character. Print Y if the prisoner had any chance of being forgiven; otherwise, print N.
Sample Input
Input
3
4 5
....S
.....
.....
F...E
4 4
...S
....
....
F..E
3 4
###S
####
E..F
Output
Y
N
N
Source
题意:S是起点,E是起点,F是火,#是墙,.是路,人从起点跑向终点,碰到火立刻死亡(即使人在终点与火相遇,也不能出去),人每分钟移动一个格子,火每分钟向上下左右四个方向蔓延一个格子,问人是否能跑出去,能输出Y,否则输出N。
两次广搜,第一次先记录火蔓延到每个格子的时间,然后搜索人跑出去的时间。
附上代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#define MP make_pair
using namespace std;
char maps[][];
int n,m;
int vis[][];
int ss[][]; ///记录火的蔓延速度
int s[][]; ///记录人的行走速度
int dx[]={,,-,};
int dy[]={,,,-}; bool judge(int x,int y)
{
if(x>= && x<=n && y>= && y<=m) return ;
return ;
} void BFS(int x,int y) ///搜索人到达终点的时间
{
int i;
queue< pair<int,int> > q;
memset(s,-,sizeof(s));
s[x][y]=;
q.push(MP(x,y));
while(!q.empty())
{
x=q.front().first;
y=q.front().second;
q.pop();
if(maps[x][y]=='E')
{
// cout<<s1.t<<endl;
printf("Y\n");
return;
}
for(i=; i<; i++)
{
int xx=x+dx[i];
int yy=y+dy[i];
if(judge(xx,yy)&&s[xx][yy] ==-&&maps[xx][yy]!='#'&&s[x][y]+<ss[xx][yy]) ///人到达这个点一定要比火快,才能走
{
s[xx][yy]=s[x][y]+;
q.push(MP(xx,yy));
}
}
}
printf("N\n");
return;
} void BFS2() ///搜索火的蔓延速度
{
queue< pair<int,int> >qq;
int i,j;
for(i=; i<=n; i++)
for(j=; j<=m; j++)
if(maps[i][j]=='F')
{
ss[i][j]=;
qq.push(MP(i,j));
}
while(!qq.empty())
{
int x=qq.front().first;
int y=qq.front().second;
qq.pop();
for(int i=; i<; i++)
{
int xx=x+dx[i];
int yy=y+dy[i];
if(judge(xx,yy)&&maps[xx][yy]!='#'&&ss[xx][yy]==-)
{
ss[xx][yy]=ss[x][y]+;
qq.push(MP(xx,yy));
}
}
}
return;
}
int main()
{
int i,j,T;
int a1,b1;
scanf("%d",&T);
getchar();
while(T--)
{
scanf("%d%d",&n,&m);
memset(vis,,sizeof(vis));
for(i=; i<=n; i++)
for(j=; j<=m; j++)
ss[i][j]=-;
int w=;
for(i=; i<=n; i++)
{
getchar();
for(j=; j<=m; j++)
{
scanf("%c",&maps[i][j]);
if(maps[i][j]=='S')
{
a1=i;
b1=j;
}
}
}
BFS2();
BFS(a1,b1);
}
return ; }
bnu 52037 Escape from Ayutthaya的更多相关文章
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- 简单明了区分escape、encodeURI和encodeURIComponent
一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...
- c#模拟js escape方法
public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...
- 【BZOJ-1340】Escape逃跑问题 最小割
1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 264 Solved: 121[Submit] ...
- LYDSY热身赛 escape
Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...
- javascript escape()函数和unescape()函数
javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- escape,encodeURI,encodeURIComponent的区别
escape是对字符串进行编码而另外两种是对URL. encodeURI方法不会对下列字符编码 ASCII字母 数字 ~!@#$&*()=:/,;?+'encodeURIComponent方法 ...
- C#针对js escape解码
在javascript 中通常用escape与unescape进行编码以方便传输. 在asp.net页面接收到这些数据以后可以使用 Microsoft.JScript.GlobalObject.une ...
随机推荐
- js创建svg元素的方法
需要JQuery <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- NOIP模拟 7.01
水灾(sliker.cpp/c/pas) 1000MS 64MB 大雨应经下了几天雨,却还是没有停的样子.土豪CCY刚从外地赚完1e元回来,知道不久除了自己别墅,其他的地方都将会被洪水淹没. CCY ...
- 考试总结 模拟28(W)
心得: 状态极差,都怪放假,上一套的T3没改完,今天考试没有一点状态,开学恐惧症.(不恐惧作业或一调但还是很茫然) T1能A掉实在是意外,杂题T1没做过,可能是人品守恒,(丢了钱今天才发现以后一定锁柜 ...
- 错觉-Info:视错觉与UI元素间的可能
ylbtech-错觉-Info:视错觉与UI元素间的可能 1.返回顶部 1. 视觉原理在当下红火的机械视觉中是必不可少的,那在我们日常工作的UI产品设计中又有什么可能性的呢?今天,我从“视错觉”这个角 ...
- [Vue CLI 3] vue inspect 的源码设计实现
首先,请记住: 它在新版本的脚手架项目里面非常重要 它有什么用呢? inspect internal webpack config 能快速地在控制台看到对应生成的 webpack 配置对象. 首先它是 ...
- java 2类与对象[学堂在线]
java的面向对象方法和特征(略) 累的声明格式 语法:先定义一个引用变量名 穿件对象 new aclock=new CLock() 没有ststaic 就是实例变量 类变量static 类变量 方法 ...
- 2018-8-10-win10-UWP-修改密码框文字水平
title author date CreateTime categories win10 UWP 修改密码框文字水平 lindexi 2018-08-10 19:17:19 +0800 2018-2 ...
- 廖雪峰Python总结4
面向对象编程 将计算机程序视为一系列的命令集合.包含: 数据 操作数据的函数 Python中,所有的数据类型都可以视为对象. 面向对象特点:封装,继承,多态. 类的函数和普通函数:类的第一个参数永远是 ...
- 数据库 Mysql-mongodb-redis
目录 1. Mysql 1.1. 介绍 1.1.1 基础 1.1.3 数据库操作 1.2. 查询 1.2.1 条件 1.2.2 聚合 1.2.3 分组 1.2.4 排序 1.2.4 分页 1.3. 高 ...
- Leetcode804.Unique Morse Code Words唯一摩尔斯密码词
国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: "a" 对应 ".-", "b" 对应 &q ...