poj_3669_Meteor Shower(BFS+预处理)
来源:互联网 发布:女士牛仔裤品牌 知乎 编辑:程序博客网 时间:2024/05/02 05:07
http://poj.org/problem?id=3669
/*思路:BFS+预处理先预处理会爆炸的区域,BFS,遇到-1则结束*/#include <iostream>#include <queue>#include <algorithm>using namespace std;int visit[1001][1001];int dx[5] = {0,0,1,0,-1};int dy[5] = {0,1,0,-1,0};typedef struct{int x,y;int step; }point;queue<point> que;int bfs(int x,int y){int cnt;if(visit[0][0] == 0) return -1;//无法逃离 if(visit[0][0] == -1) return 0; //安全,无需逃离 point s,cur,next;s.x = x;s.y = y;s.step = 0;que.push(s);while(!que.empty()){cur = que.front();que.pop();for(int i = 0;i < 5;i++){next.x = cur.x + dx[i];next.y = cur.y + dy[i];next.step = cur.step + 1;if(next.x >= 0 && next.y >= 0 && next.y < 1001 && next.x < 1001){if(visit[next.x][next.y] == -1){return next.step;}if(next.step < visit[next.x][next.y]){visit[next.x][next.y] = next.step;//记录最小的步数 que.push(next);}} } } return -1;}int main(){int m; while(cin >> m){ int x,y,t,xx,yy; memset(visit,-1,sizeof(visit)); for(int i = 0;i < m;i++) { cin >> x >> y >> t; for(int i = 0;i <= 4;i++) { xx = x + dx[i]; yy = y + dy[i]; if(xx >= 0 && yy >= 0 && xx < 1001 && yy < 1001)//保证在有限区域内 { if(visit[xx][yy] == -1) visit[xx][yy] = t; else visit[xx][yy] = min(visit[xx][yy],t);} } } cout << bfs(0,0) << "\n"; } return 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+预处理
- POJ3669 Meteor Shower BFS
- poj3669Meteor Shower(bfs)
- poj3669 Meteor Shower BFS
- POJ3669 Meteor Shower(BFS)
- POJ3669 Meteor Shower 【BFS】
- POJ_3669 Meteor Shower(BFS)
- POJ3669Meteor Shower【BFS】
- POJ3669-Meteor Shower-BFS
- poj3669 Meteor Shower bfs
- Poj3669 meteor shower bfs
- POJ3669Meteor Shower(bfs)
- POJ3669 Meteor Shower (BFS)
- Meteor Shower (bfs)
- Clojure版Selenium WebDriver笔记——如何使用sendKeys方法
- linux与windows双系统时,linux下耳机使用正常,windows下耳机却没声音
- 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活//0-1背包和多重背包
- 【Python】写了个比较见功力的函数
- 设置core dump 文件生成目录
- poj_3669_Meteor Shower(BFS+预处理)
- 20150208学习总结
- JFinal开发8个常见问题
- uva 514 - Rails
- Android Wifi模块 ScanResult类源码分析(基于Android 5.0)
- This is my first article in csdn.
- zoj 3195 Design the city
- POJ - 2533 Longest Ordered Subsequence
- Android 自定义控件 轻松实现360软件详情页