Description

The Barareh village is on fire due to the attack of the virtual enemy. Several places are already on fire and the fire is spreading fast to other places. Khorzookhan who is the only person remaining alive in the war with the virtual enemy, tries to rescue himself by reaching to the only helicopter in the Barareh villiage. Suppose the Barareh village is represented by an n × m grid. At the initial time, some grid cells are on fire. If a cell catches fire at time x, all its 8 vertex-neighboring cells will catch fire at time x + k. If a cell catches fire, it will be on fire forever. At the initial time, Khorzookhan stands at cell s and the helicopter is located at cell t. At any time x, Khorzookhan can move from its current cell to one of four edge-neighboring cells, located at the left, right, top, or bottom of its current cell if that cell is not on fire at time x + 1. Note that each move takes one second. Your task is to write a program to find the shortest path from s to t avoiding fire.

Input

There are multiple test cases in the input. The first line of each test case contains three positive integers n, m and k (1 ⩽ n,m,k ⩽ 100), where n and m indicate the size of the test case grid n × m, and k denotes the growth rate of fire. The next n lines, each contains a string of length m, where the jth character of the ith line represents the cell (i, j) of the grid. Cells which are on fire at time 0, are presented by character “f”. There may exist no “f” in the test case. The helicopter and Khorzookhan are located at cells presented by “t” and “s”, respectively. Other cells are filled by “-” characters. The input terminates with a line containing “0 0 0” which should not be processed.

Output

For each test case, output a line containing the shortest time to reach t from s avoiding fire. If it is impossible to reach t from s, write “Impossible” in the output.

Sample Input

7 7 2
f------
-f---f-
----f--
-------
------f
---s---
t----f-
3 4 1
t--f
--s-
----
2 2 1
st
f-
2 2 2
st
f-
0 0 0

Sample Output

4
Impossible
Impossible
1 emmmm,一个预处理的bfs,开始放在中间更新,写的超级麻烦还过不了,后来预处理过了。根据判断这个点的八个方向是否有火来判断他是否会变成火,不要根据有火来使四周的变成火,否则会出错。
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 105
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
int n, m, k, sx, sy, ex, ey, dx[] = { , , , - }, dy[] = { , -, , }, vis[maxn][maxn];
int tx[] = { , , , -, , , -, - }, ty[] = { , -, , , , -, , - }, mapn[maxn][maxn][maxn];
struct node{
int step, x, y;
};
void bfs() {
node p;
p.x = sx, p.y = sy, p.step = ;
vis[sx][sy] = ;
queue<node> q;
q.push(p);
while( !q.empty() ) {
node now = q.front();
q.pop();
if( now.x == ex && now.y == ey ) {
cout << now.step << endl;
return ;
}
for( int i = ; i < ; i ++ ) {
int xx = now.x + dx[i];
int yy = now.y + dy[i];
if( xx >= && xx < n && yy >= && yy < m && !vis[xx][yy] && mapn[(now.step+)/k][xx][yy] ) {
node tmp;
tmp.x = xx, tmp.y = yy, tmp.step = now.step + ;
q.push(tmp);
vis[xx][yy] = ;
}
}
}
cout << "Impossible" << endl;
}
int main() {
while( cin >> n >> m >> k ) {
if( !n && !m && !k ) {
break;
}
memset( vis, , sizeof(vis) );
for( int i = ; i < n; i ++ ) {
for( int j = ; j < m; j ++ ) {
char t;
cin >> t;
if( t == 's' ) {
mapn[][i][j] = ;
sx = i, sy = j;
} else if( t == 't' ) {
mapn[][i][j] = ;
ex = i, ey = j;
} else if( t == '-' ) {
mapn[][i][j] = ;
} else if( t == 'f' ){
mapn[][i][j] = ;
}
}
}
//预处理
for( int p = ; p < max( n, m ); p ++ ) {
for( int i = ; i < n; i ++ ) {
for( int j = ; j < m; j ++ ) {
mapn[p][i][j] = ;
for( int z = ; z < ; z ++ ) {
int xx = i + tx[z];
int yy = j + ty[z];
if( xx >= && xx < n && yy >= && yy < m && !mapn[p-][xx][yy] ) {
mapn[p][i][j] = ;
}
}
}
}
}
bfs();
}
return ;
}

2018湖南多校第二场-20180407 Barareh on Fire的更多相关文章

  1. 2018湖南多校第二场-20180407 Column Addition

    Description A multi-digit column addition is a formula on adding two integers written like this:

  2. 2019牛客多校第二场 A Eddy Walker(概率推公式)

    2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...

  3. 2018 Multi-University Training Contest 2 杭电多校第二场

    开始逐渐习惯被多校虐orz  菜是原罪 1004  Game    (hdoj 6312) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6312 虽然披着 ...

  4. 2019年湖南多校第一场||2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

    第一场多校就打的这么惨,只能说自己太菜了,还需继续努力啊- 题目链接: GYM链接:https://codeforces.com/gym/101933 CSU链接:http://acm.csu.edu ...

  5. hdu6312 2018杭电多校第二场 1004 D Game 博弈

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. 2018牛客多校第二场a题

    一个人可以走一步或者跳x步,但不能连着跳,问到这个区间里有几种走法 考虑两种状态  对于这一点,我可以走过来,前面是怎么样的我不用管,也可以跳过来但是,跳过来必须保证前一步是走的 dp[i][0]表示 ...

  7. 2018杭电多校第二场1003(DFS,欧拉回路)

    #include<bits/stdc++.h>using namespace std;int n,m;int x,y;int num,cnt;int degree[100007],vis[ ...

  8. 2019 湖南多校第一场(2018~2019NCPC) 题解

    解题过程 开场shl过B,C,然后lfw写J,J WA了以后shl写A,但是因为OJ上空间开小WA了,而不是MLE?,J加了特判过了.之后一直在检查A错哪了,直到qt发现问题改了空间,浪费许多时间,但 ...

  9. 2014多校第二场1011 || HDU 4882 ZCC Loves Codefires (贪心)

    题目链接 题意 : 给出n个问题,每个问题有两个参数,一个ei(所要耗费的时间),一个ki(能得到的score).每道问题需要耗费:(当前耗费的时间)*ki,问怎样组合问题的处理顺序可以使得耗费达到最 ...

随机推荐

  1. sed流编辑器

    一.前言 (一).sed 工作流程 sed 是一种在线的.非交互式的流编辑器,它一次处理一行内容.处理时,把当做前处理的行存储在临时缓存区中,成为“模式空间”(pattern space),接着用se ...

  2. 【Java例题】5.3 字符统计

    3.分别统计一个字符串中大写字母.小写字母.数字. 汉字以及其它字符的个数. package chapter5; import java.util.Scanner; public class demo ...

  3. Spark 系列(三)—— 弹性式数据集RDDs

    一.RDD简介 RDD 全称为 Resilient Distributed Datasets,是 Spark 最基本的数据抽象,它是只读的.分区记录的集合,支持并行操作,可以由外部数据集或其他 RDD ...

  4. appcan IDE 无法 请求数据

    我们4月27号从4.0.1升级到4.0.2后,IDE本地预览get请求不到数据.但是在线打包安装到手机又是正常的. 先下载 "uexXmlHttpMgr.rar",下载链接:htt ...

  5. 号外!号外!呼叫所有.NET桌面和移动开发人员!

    8月7日微软在官方博客发起了一次关于.NET桌面和移动开发的调查问卷,直到今天看博客才知道.这次调查的重点是关于.NET桌面开发技术的跨平台,于是我喜大普奔,奔走相告,希望有这方面需求的朋友们都能去参 ...

  6. (十三)c#Winform自定义控件-导航菜单

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  7. 7.17 正则表达式 re模块

    在介绍正则表达式和re模块之前,先简要介绍一下 正则表达式与re模块的关系 1.正则表达式是一门独立的技术,任何语言均可使用 2.python中要想使用正则表达式需要通过re模块 正则表达式 元字符 ...

  8. Zabbix遇到的问题集锦

    一.Web界面上显示Zabbix server is not running 二.Zabbix显示中文字体 三.利用Python发送告警注意细节 四.zabbix上发告警信息不发恢复信息 五.Agen ...

  9. vue自定义组件中的v-model简单解释

    在使用iview框架的时候,经常会看到组件用v-model双向绑定数据,与传统步骤父组件通过props传值子组件,子组件发送$emit来修改值相比,这种方式避免操作子组件的同时再操作父组件,显得子组件 ...

  10. CSS3的滤镜filter属性

    css3的滤镜filter属性,可以对网页中的图片进行类似Photoshop图片处理的效果,例如背景的毛玻璃效果.老照片(黑白照片).火焰效果等. 一.blur(px)高斯模糊 二.brightnes ...