poj 3669 bfs+预处理
来源:互联网 发布:天津哪里有mac专柜 编辑:程序博客网 时间:2024/06/06 05:17
点击打开链接
#include <iostream>#include <algorithm>#include <cstring>#include <queue>using namespace std;const int MAX=305;typedef struct{int x;int y;}Move;Move move[4]={{-1,0},{1,0},{0,-1},{0,1}};struct Node{int x;int y;int t;Node(int x1,int y1,int t1):x(x1),y(y1),t(t1){}};queue<Node> q; //到达该点的最短时间 int time[MAX][MAX],visit[MAX][MAX];// meteor落到 (i,j)的最早时间 若time[i][j]=-1 则为安全点 bool bfs() //从0点走到安全点的最短时间 {q.push(Node(0,0,0));visit[0][0]=1;while(!q.empty()){Node n=q.front();q.pop();int x=n.x,y=n.y;if(time[x][y]==1<<11) //到达安全点 {cout<<n.t;return 1;}for(int i=0;i<4;i++){int a=x+move[i].x;int b=y+move[i].y;if(a>=0&&a<MAX&&b>=0&&b<MAX&&!visit[a][b]) {int tmp=n.t+1;if(tmp>=time[a][b]) //不能走到已经被meteor destory的点{continue;}visit[a][b]=1;q.push(Node(a,b,tmp));}}}return false;}int main(){int m,a,b,x,y,t;cin>>m;memset(visit,0,sizeof(visit));for(int i=0;i<MAX;i++){for(int j=0;j<MAX;j++){time[i][j]=1<<11; //没被 meteor砸到的点 }}for(int i=0;i<m;i++){cin>>x>>y>>t;time[x][y]=min(time[x][y],t); // meteor到(x,y)的最早下落时间 (时间t大于等于time[x][y]则不能走该点)for(int j=0;j<4;j++){a=x+move[j].x;b=y+move[j].y;if(a>=0&&a<MAX&&b>=0&&b<MAX){time[a][b]=min(time[a][b],t);}}}if(time[0][0]==0||!bfs()){cout<<-1<<endl;}return 0;}
0 0
- poj 3669 bfs+预处理
- POJ 3669 Meteor Shower (BFS + 预处理)
- poj 3669 bfs水题预处理
- POJ 3669 Meteor Shower(预处理 + BFS)
- POJ 3669 Meteor Shower【BFS + 预处理】
- [POJ](3669)Meteor Shower ---- bfs+预处理
- BFS+预处理 POJ
- POJ-2688:Cleaning Robot(bfs预处理+dfs)
- poj 3162 线段树 hdu 4123 bfs + RMQ预处理
- POJ 3601 Escape from Enemy Territory (二分+BFS+预处理)
- poj 2049 Finding Nemo 建迷宫预处理+优先队列bfs
- poj 1924 The Treasure (bfs+地图预处理)
- poj 3501 Escape from Enemy Territory(预处理&二分&bfs)
- poj 3162 线段树 hdu 4123 bfs + RMQ预处理
- POJ 3669 BFS
- poj 3669 (BFS)
- poj 3669 bfs
- poj 3669 bfs
- Maven (POM+约定+生命周期 + 依赖) 战略分析
- c++实验7-函数
- Android 个人博客客户端——My CSDN 的实现(5)
- 二叉树的非递归建立(一)
- 一周乱弹(1,eclipse 远程调试tomcat。2,常量类的作用。3,通过花生壳实现远程连接 端口:3389),4oracle查询日期5,bootstrap文本样式6,6 js四舍五入
- poj 3669 bfs+预处理
- Android 6.0运行时权限
- LocalNote,让你像使用本地文件一样使用印象笔记(支持 markdown 格式)
- Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)
- Activity的入场动画合集
- 深入浅出Mybatis系列(十)---SQL执行流程分析(源码篇)
- Apache自带的 ab(apache benchmark,基准测试,压力测试)使用
- Http 和Https 简单分析
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure【分治+BFS】