[kuangbin带你飞]专题一 简单搜索-J - Fire!
来源:互联网 发布:知乎 毕业一年后 编辑:程序博客网 时间:2024/05/18 03:30
分析:先确定火的扩散速度,当J走到该格,若时间小于扩散到该格的时间则无事,否则烧死
#include <cstdio>#include <queue>#include <iostream>#include <cstring>using namespace std;typedef long long ll;typedef pair <int, int > P;typedef struct {int a;int b;int wal;}dat;dat p;queue <dat> f;char temp[1005][1005];int maze[1005][1005];int n, m, ans, vis[1005][1005], dir[][2] = { 0,1, 1,0, 0,-1, -1,0 };dat star;void init(){cin >> n >> m;//scanf("%d %d", &n, &m);ans = 100000; star.a = 0, star.b = 0;memset(vis, 0, sizeof vis);memset(maze, 0, sizeof maze);for (int i = 1; i <= n; i++)cin >> temp[i] + 1;//scanf("%s", temp[i] + 1);for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++){if (temp[i][j] == 'J'){star.a = i;star.b = j;maze[i][j] = 0;}if (temp[i][j] == '.')maze[i][j] = 0;if (temp[i][j] == '#')maze[i][j] = -1;if (temp[i][j] == 'F'){p.a = i, p.b = j;maze[i][j] = 0;vis[i][j] = 1;p.wal = 0;f.push(p);}}//vis[star.a][star.b] = 1;}void fire(){dat now, nex;while (f.size()){now = f.front();f.pop();for (int i = 0; i<4; i++){int a, b;a = now.a + dir[i][0], b = now.b + dir[i][1];nex.a = a, nex.b = b;nex.wal = now.wal + 1;if (1 <= a&&a <= n && 1 <= b&&b <= m)if (maze[a][b] == 0&&vis[a][b]==0){maze[a][b] = now.wal + 1;f.push(nex);vis[a][b] = 1;}}}}void bfs(){memset(vis, 0, sizeof vis);vis[star.a][star.b] = 1;queue <dat> q;star.wal = 0;q.push(star);// cout<<maze[1][1]<<endl;while (q.size()){dat now = q.front();q.pop();if (now.a == 0 || now.a>n || now.b == 0 || now.b>m){if (ans > now.wal){ans = now.wal;return;}}if (maze[now.a][now.b] <= now.wal&&maze[now.a][now.b]!=0 ){continue;}for (int i = 0; i<4; i++){int a = now.a + dir[i][0], b = now.b + dir[i][1];dat nex;nex.a = a, nex.b = b;nex.wal = now.wal + 1;if (vis[nex.a][nex.b] == 0 && maze[nex.a][nex.b] != -1){q.push(nex);vis[nex.a][nex.b] = 1;}}}}void solve(){init();fire();bfs();if (ans != 100000)printf("%d\n", ans );elseprintf("IMPOSSIBLE\n");}int main(void){int t;cin >> t;while (t--){solve();}}
0 0
- [kuangbin带你飞]专题一 简单搜索-J - Fire!
- [kuangbin带你飞]专题一 简单搜索J - Fire!(UVA 11624)
- [kuangbin带你飞]专题一 简单搜索 J - Fire! UVA 11624
- Fire Game [kuangbin带你飞]专题一 简单搜索
- [kuangbin带你飞]专题一 简单搜索 J
- UVA 11624 Fire!(kuangbin带你飞 专题一:简单搜索)
- FZU 2150 Fire Game(kuangbin带你飞 专题一:简单搜索)
- [kuangbin带你飞]专题一 简单搜索I - Fire Game(FZU 2150)
- [kuangbin带你飞]专题一 简单搜索 I - Fire Game FZU 2150
- [kuangbin带你飞]专题一 简单搜索 -I - Fire Game
- FZU 2150 Fire Game ([kuangbin带你飞]专题一 简单搜索)
- UVA 11624 Fire! ([kuangbin带你飞]专题一 简单搜索)
- [kuangbin带你飞]专题一 简单搜索 J UVA 11624
- [kuangbin神带你飞]专题一 简单搜索
- kuangbin带你飞 专题一 简单搜索 (题解)
- [kuangbin带你飞]专题一 简单搜索 总结
- Kuangbin带你飞专题一 简单搜索
- [kuangbin带你飞]专题一 简单搜索 D - Fliptile
- hdoj1002
- Spring核心之依赖注入(三)
- poj 1088 滑雪
- Android开发艺术探索学习笔记之Activity(1)生命周期
- OSGI入门环境搭建及相关概念
- [kuangbin带你飞]专题一 简单搜索-J - Fire!
- Android活动被回收了的处理方式
- Codeforces 667C Reberland Linguistics (DP)
- 面试之路(16)-归并排序详解(MergeSort)递归和非递归实现
- MySQL 下 ROW_NUMBER / DENSE_RANK / RANK 的实现
- 两位数乘一位数
- leetcode 062 Unique Paths
- jsp页面中插入css样式的三种方法总结
- 练习