POJ 3669 Meteor Shower(BFS)
来源:互联网 发布:沈阳纳森网络靠谱吗 编辑:程序博客网 时间:2024/05/17 05:11
题目链接:http://poj.org/problem?id=3669
题意:给定一个平面,在某些时刻下流星雨,当流星雨落在(x,y)点时,该点及四周的四个点都被破坏。
人从(0,0)点开始走,每秒沿四个方走一步,问最少要走多少步才能走到安全的地点。其中0<=x,y<=300,但是人所活动的区域是第一象限,所以比范围这个要大
思路:广搜处理,但是要注意一些细节,比如一开始如果就在安全区,那就直接返回0,如果流星在0秒时落下那就直接返回-1,而且同一地点可能下落多块流星,所以需要记录某点流星落下的最小时间
#include<cstdio>#include<queue>#include<string.h>#define M 310#define INF 1e9using namespace std;struct node{ int x; int y; int w;};int map[M][M];int vis[M][M];int dis[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};queue <node> q;int bfs(int a, int b){ int t; node s, e; memset(vis, 0, sizeof(vis)); s.x = 0, s.y = 0, s.w = 0; q.push(s); if(map[0][0] == INF) return 0; if(map[0][0] == 0) return -1; while(!q.empty()) { s = q.front(); for(t = 0; t < 4; t++) { e.x = s.x + dis[t][0]; e.y = s.y + dis[t][1]; e.w = s.w + 1; if(e.x >= 0 && e.y >= 0 && e.x <= M && e.y <= M && map[e.x][e.y] > e.w && ! vis[e.x][e.y]) { if(map[e.x][e.y] == INF) return e.w; vis[e.x][e.y] = 1; q.push(e); } } q.pop(); } return -1;}int main(){ int N, i, j; int x, y, ti; scanf("%d", &N); for(i = 0; i <= M; i++) for(j = 0; j <= M; j++) map[i][j] = INF; for(i = 0; i < N; i++) { scanf("%d%d%d", &x, &y, &ti); if(map[x][y] > ti) map[x][y] = ti; if(map[x+1][y] > ti) map[x + 1][y] = ti; if(map[x][y+1]>ti) map[x][y + 1] = ti; if(x > 0 && map[x-1][y] > ti) map[x - 1][y] = ti; if(y > 0 && map[x][y-1] > ti) map[x][y - 1] = ti; } printf("%d\n", bfs(0, 0));}
0 0
- poj 3669 Meteor Shower (bfs)
- POJ 3669-Meteor Shower(BFS)
- POJ 3669 Meteor Shower(BFS)
- POJ 3669 Meteor Shower BFS
- POJ 3669 Meteor Shower(BFS)
- POJ-3669 Meteor Shower BFS
- Meteor Shower (poj 3669 bfs)
- [bfs] poj 3669 Meteor Shower
- poj 3669 Meteor Shower 【BFS】
- Poj 3669 Meteor Shower【bfs】
- POJ 3669 Meteor Shower (BFS)
- poj 3669 Meteor Shower(bfs)
- POJ 3669:Meteor Shower(bfs)
- [POJ] 3669 Meteor Shower [BFS]
- POJ 3669 Meteor Shower BFS 水~
- POJ 3669 Meteor Shower (BFS)
- POJ 3669 Meteor Shower (BFS + 预处理)
- POJ 3669 Meteor Shower (bfs)
- jQuery获取Select选择的Text和 Value
- String类__ 上
- Android软件开发之盘点自定义View界面大合集(二)
- 小数据
- freemarker学习
- POJ 3669 Meteor Shower(BFS)
- Epoll在LT和ET模式下的读写方式
- JavaScript implementations of standard and secure cryptographic algorithms
- 迅雷7手动去广告
- USB基础知识2
- 使用扩展方法,向现有类型“添加”方法
- 怎么查看unix下被占用的某端口的进程?
- Tomcat工作原理 、JVM内存溢出及合理配置、配置文件详解
- MySQL复制表数据到新表的方法