Nyoj 284 坦克大战
来源:互联网 发布:淘宝男装原创品牌 编辑:程序博客网 时间:2024/04/30 01:19
题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=284
跟zoj1649 Rescue 相当的类似!http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649
参考:http://blog.csdn.net/hearthougan/article/details/12377477
#include <iostream>#include <cstring>#include <cstdio>#include <queue>#include <cmath>using namespace std;const int MAXN = 310;const int INF = 0xffffff;struct Node{ int x, y; int step; Node() { x = y = 0; step = 0; }};char Graph[MAXN][MAXN];int MinTime[MAXN][MAXN];int dir[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};Node TargetPos;int row, col;bool Is_CanGo(Node CurPos){ if(CurPos.x < 0 || CurPos.x >= row || CurPos.y < 0 || CurPos.y >= col || Graph[CurPos.x][CurPos.y] == 'S' || Graph[CurPos.x][CurPos.y] == 'R') return false; return true;}void BFS(Node s){ queue <Node> Que; Que.push(s); while(!Que.empty()) { Node CurPos = Que.front(); Que.pop(); for(int i = 0; i < 4; ++i) { Node t; t.x = CurPos.x + dir[i][0]; t.y = CurPos.y + dir[i][1]; if(Is_CanGo(t)) { t.step = CurPos.step + 1; if(Graph[t.x][t.y] == 'B') t.step++; if(MinTime[t.x][t.y] > t.step) { MinTime[t.x][t.y] = t.step; Que.push(t); } } } } return ;}int main(){ Node StartPos; while(~scanf("%d %d", &row, &col) && (row + col)) { for(int i = 0; i < row; ++i) { scanf("%s", Graph[i]); for(int j = 0; j < col; ++j) { MinTime[i][j] = INF; if(Graph[i][j] == 'Y') StartPos.x = i, StartPos.y = j; else if(Graph[i][j] == 'T') TargetPos.x = i, TargetPos.y = j; } } MinTime[StartPos.x][StartPos.y] = 0; StartPos.step = 0; BFS( StartPos ); int t = MinTime[TargetPos.x][TargetPos.y]; if(t != INF) printf("%d\n", t); else printf("-1\n"); } return 0;}
0 0
- nyoj-284-坦克大战
- NYOJ-284 坦克大战
- Nyoj 284 坦克大战
- NYOJ-284 坦克大战
- nyoj 284 坦克大战
- nyoj 284 坦克大战
- nyoj 284 坦克大战
- NYOJ 284 坦克大战
- NYOJ 284 坦克大战
- nyoj 284 坦克大战
- nyoj 284 坦克大战
- 南阳(NYOJ)284 坦克大战
- NYOJ 284 坦克大战(BFS)
- NYOJ 284 坦克大战【优先队列】
- nyoj 284 坦克大战 简单搜索
- NYOJ 284 坦克大战 【BFS】+【优先队列】
- NYOJ 284 坦克大战 【BFS】+【优先队列】
- nyoj 284 坦克大战 【bfs(简单题)】
- 插入排序及优化
- Django中的用户与Authentication
- wordpress获取指定标签下所有文章
- Ubuntu 12.04 下jdk的安装和java环境配置
- 美莱帝灯饰加盟骗子
- Nyoj 284 坦克大战
- 线段树模板一
- 中文字符编码的相互转换(三)
- 学习图片翻转的代码
- bzoj2393 容斥原理
- richEdit中插入图片
- QT QMenu美化备忘
- 初级程序员进阶之路
- 按照主关键字和次关键字排序