2018湖南多校第二场-20180407 Barareh on Fire
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的更多相关文章
- 2018湖南多校第二场-20180407 Column Addition
Description A multi-digit column addition is a formula on adding two integers written like this:
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- 2018 Multi-University Training Contest 2 杭电多校第二场
开始逐渐习惯被多校虐orz 菜是原罪 1004 Game (hdoj 6312) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6312 虽然披着 ...
- 2019年湖南多校第一场||2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)
第一场多校就打的这么惨,只能说自己太菜了,还需继续努力啊- 题目链接: GYM链接:https://codeforces.com/gym/101933 CSU链接:http://acm.csu.edu ...
- hdu6312 2018杭电多校第二场 1004 D Game 博弈
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 2018牛客多校第二场a题
一个人可以走一步或者跳x步,但不能连着跳,问到这个区间里有几种走法 考虑两种状态 对于这一点,我可以走过来,前面是怎么样的我不用管,也可以跳过来但是,跳过来必须保证前一步是走的 dp[i][0]表示 ...
- 2018杭电多校第二场1003(DFS,欧拉回路)
#include<bits/stdc++.h>using namespace std;int n,m;int x,y;int num,cnt;int degree[100007],vis[ ...
- 2019 湖南多校第一场(2018~2019NCPC) 题解
解题过程 开场shl过B,C,然后lfw写J,J WA了以后shl写A,但是因为OJ上空间开小WA了,而不是MLE?,J加了特判过了.之后一直在检查A错哪了,直到qt发现问题改了空间,浪费许多时间,但 ...
- 2014多校第二场1011 || HDU 4882 ZCC Loves Codefires (贪心)
题目链接 题意 : 给出n个问题,每个问题有两个参数,一个ei(所要耗费的时间),一个ki(能得到的score).每道问题需要耗费:(当前耗费的时间)*ki,问怎样组合问题的处理顺序可以使得耗费达到最 ...
随机推荐
- NYOJ 53 最少步数
题 目 http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=58 思路借鉴 DFS-Deep First Search-深度优先 ...
- Python开发异步任务Celery的使用教程!
1. 生产者消费者设计模式 最常用的解耦方式之一,寻找中间人(broker)搭桥,保证两个业务没有直接关联.我们称这一解耦方式为:生产者消费者设计模式 2.中间人broker 示例:此处演示Redis ...
- JAVA并发编程之倒计数器CountDownLatch
CountDownLatch 的使用场景:在主线程中开启多线程去并行执行任务,并且主线程需要等待所有子线程执行完毕后汇总返回结果. 我把源码中的英文注释全部删除,写上自己的注释.就剩下 70 行不到的 ...
- 有容云-PPT | 当微服务遇见容器
编者注: 本文为10月29日有容云高级技术顾问龙淼在Docker Live时代线下系列-广州站中演讲的PPT,本次线下沙龙为有容云倾力打造Docker Live时代系列主题线下沙龙,每月一期畅聊容器技 ...
- 素数筛法(Eratosthenes筛法)
介绍 Eratosthenes筛法,又名埃氏筛法,对于求1~n区间内的素数,时间复杂度为n log n,对于10^6^ 以内的数比较合适,再超出此范围的就不建议用该方法了. 筛法的思想特别简单: 对于 ...
- git语句(后续补充)
如果你是windows用户,需要下载一个git应用程序,一路点就行,没有什么需要注意的地方 安装完成后在任一文件夹内右键都有显示,单击git bash here即可 简易的命令行入门教程: Git 全 ...
- flink 1.7.2 安装详解
##flink 1.7.2 安装需要java环境 下载地址 https://flink.apache.org/downloads.html#1.单机版 #创建用户flinkuseradd flink ...
- 使用webpack---安装webpack和webpack-dev-server
1.先确保安装了最新版的Node.js和NPM,并已经了解NPM的基本用法 (以下使用cmd命令行进行) 2.安装webpack (1)全局安装 $ npm install webpack -g ...
- thinkPHP 获得当前请求的全部常量信息
tp框架提供了常量: http://网址/shop/index.php/分组/控制器/操作方法/名称1/值/名称2/值 __MODULE__: 路由地址分组信息 (/shop/index.php/分组 ...
- Jenkins使用aqua-microscanner-plugin进行容器漏洞扫描
官方地址:https://github.com/jenkinsci/aqua-microscanner-plugin Step1 在jenkins安装"Aqua MicroScanner&q ...