POJ3669 Meteor Shower(BFS)
来源:互联网 发布:oracle 输入数据 编辑:程序博客网 时间:2024/05/22 18:21
题意解析:在平面坐标系中,从原点出发,上下左右四个方向可走,一些点在T[i]秒后会有炸弹降落。在T秒包括T秒后这些点(包括周围四个方向的点)都不能到达,求如何在最短时间内到达安全地点。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>#include<vector>#include<cmath>#define ll __int64#define INF 0x3f3f3fusing namespace std;int n;int dir[4][2]= {{1,0},{0,1},{0,-1},{-1,0}};bool vis[400][400];struct Node{ int x,y,tm; int Time; Node() { tm=1001; Time=0; }} map[400][400];Node p;int go(int x,int y,int t){ int minT=t; for(int i=0; i<4; i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(xx<0||yy<0) continue; minT=min(map[xx][yy].tm,minT); } return minT;}int bfs(){ queue<Node>pq; Node q; p.x=0; p.y=0; p.tm=map[0][0].tm; pq.push(p); while(!pq.empty()) { q=pq.front(); pq.pop(); for(int i=0; i<4; i++) { p.x=q.x+dir[i][0]; p.y=q.y+dir[i][1]; p.Time=q.Time+1; if(p.x<0||p.y<0||vis[p.x][p.y]) continue; p.tm=map[p.x][p.y].tm; if(p.Time>p.tm) continue; int temp=go(p.x,p.y,p.tm); if(temp==1001) return p.Time; if(temp<=p.Time) continue; vis[p.x][p.y]=true; pq.push(p); } } return -1;}int main(){ //freopen("d:\\test.txt","r",stdin); cin>>n; for(int i=0; i<n; i++) { int a,b,t; cin>>a>>b>>t; map[a][b].x=a; map[a][b].y=b; map[a][b].tm=t; } memset(vis,false,sizeof(vis)); cout<<bfs()<<endl; return 0;}
0 0
- POJ3669 Meteor Shower BFS
- poj3669 Meteor Shower BFS
- POJ3669 Meteor Shower(BFS)
- POJ3669 Meteor Shower 【BFS】
- POJ3669-Meteor Shower-BFS
- poj3669 Meteor Shower bfs
- Poj3669 meteor shower bfs
- POJ3669 Meteor Shower (BFS)
- POJ3669 Meteor Shower(bfs)
- POJ3669-Meteor Shower(BFS)
- poj3669 Meteor Shower(bfs java)
- 宽度优先搜索(BFS):POJ3669--Meteor Shower
- POJ3669——Meteor Shower(BFS)
- POJ3669-Meteor Shower
- POJ3669 Meteor Shower
- 【poj3669】Meteor Shower 搜索
- poj3669-Meteor Shower
- POJ3669 Meteor Shower
- Java 向Hbase表插入数据报(org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apac
- Keil5创建STM32工程
- Java客户端连接HBase报错:Not a host:port pair
- 可编程图形硬件发展历史,以及CPU VS CPU
- Hadoop+HBase 安装配置
- POJ3669 Meteor Shower(BFS)
- 割耳法
- 【OpenCV学习笔记】【教程翻译】二(车牌识别算法框架)
- python笔记2 常见的算术运算符
- 第三周周工作表
- Oracle数据表测试笔记-角色管理-excel数据导入
- isPalidrome()函数检测回文字符串
- 游戏框架其九:3D图像之数学基础
- 经典中的博弈:第一章 C++的Hello,World!