[ACM] UVa 11624 Fire!
来源:互联网 发布:国际网络推广工程师 编辑:程序博客网 时间:2024/05/10 18:20
#include<iostream>#include<queue>#include<cstring>using namespace std;const int MAXDATA = 1005;const int NOTV = -1;const int OPR[4][2] = { 0, 1, 0, -1, 1, 0, -1, 0};struct d2Pos { int x, y, d;};int X__, Y__, R__;char g[MAXDATA][MAXDATA];int fire[MAXDATA][MAXDATA], joev[MAXDATA][MAXDATA];queue<d2Pos> fireQ;d2Pos joe;void readg() { R__ = 0; while (!fireQ.empty()) fireQ.pop(); cin >> X__ >> Y__; for (int i = 0; i < X__; i++) { for (int j = 0; j < Y__; j++) { char t; cin >> t; g[i][j] = t; joev[i][j] = NOTV; switch (t) { case 'J': joev[i][j] = 0; fire[i][j] = NOTV; joe.x = i; joe.y = j; joe.d = 0; case '.': fire[i][j] = NOTV; break; case 'F': fire[i][j] = 0; d2Pos t1; t1.x = i; t1.y = j; t1.d = 0; fireQ.push(t1); } } }}bool inmaze(d2Pos t) { return (t.x >= 0 && t.y >= 0 && t.x < X__ && t.y < Y__);}void Search_Fire() { d2Pos t, v; while (!fireQ.empty()) { t = fireQ.front(); fireQ.pop(); for (int i = 0; i < 4; i++) { v.d = t.d + 1; v.x = t.x + OPR[i][0]; v.y = t.y + OPR[i][1]; if (!inmaze(v)) continue; if (g[v.x][v.y] == '#') continue; if (fire[v.x][v.y] != NOTV) continue; fireQ.push(v); fire[v.x][v.y] = v.d; } }}void Search_Joe() { queue<d2Pos> Q; Q.push(joe); d2Pos t, v; while (!Q.empty()) { t = Q.front(); Q.pop(); if (t.x == 0 || t.y == 0 || t.x == X__ - 1 || t.y == Y__ - 1) { R__ = t.d + 1; return; } for (int i = 0; i < 4; i++) { v.d = t.d + 1; v.x = t.x + OPR[i][0]; v.y = t.y + OPR[i][1]; if (!inmaze(v)) continue; if (g[v.x][v.y] == '#') continue; if (fire[v.x][v.y] != NOTV && v.d >= fire[v.x][v.y]) continue; if (joev[v.x][v.y] != -1) continue; Q.push(v); joev[v.x][v.y] = v.d; } }}int main() { int T; cin >> T; while (T--) { readg(); Search_Fire(); Search_Joe(); if (R__ == 0) cout << "IMPOSSIBLE" << endl; else cout << R__ << endl; } return 0;}
阅读全文
1 0
- [ACM] UVa 11624 Fire!
- UVa 11624 - Fire!
- UVA 11624 - Fire!
- Uva-11624-Fire!
- uva 11624 Fire!
- uva 11624 - Fire!
- UVa 11624 - Fire!
- UVa 11624 Fire!
- UVA 11624 BFS Fire
- UVa Fire! 11624 (BFS)
- UVA - 11624 Fire!
- uva 11624 - Fire! bfs
- UVA 11624 Fire!
- UVa 11624 Fire! / BFS
- UVa:11624 Fire!
- UVA - 11624 Fire!
- UVa 11624 - Fire!
- uva 11624 Fire
- J-Link v8固件丢失修复
- 函数
- JFrame的层次结构究竟是什么样的,什么又是ContentPane()
- [UOJ261]天天爱跑步
- 线性判别分析(Linear Discriminant Analysis)(一)
- [ACM] UVa 11624 Fire!
- java.lang.IncompatibleClassChangeError: BasicHttpParams
- 解决ubuntu安装 libboost-all-dev 时出现“有几个软件包无法下载....”的错误
- Kotlin系列:1.配置Kotlin
- sql补充
- 使用ionic3/ag4编写模仿百度钱包的demo
- C语言基础-指针和数组的关系17
- slice和splice的区别
- dancing links(待补。。。。。)