poj3669-Meteor Shower
来源:互联网 发布:天互数据张彦华 编辑:程序博客网 时间:2024/05/21 01:29
思路:
把图标记后有条件的bfs
#include <stdio.h>#include <cstring>#include <algorithm>#include <iostream>#include <vector>#include <queue>using namespace std;const int inf=0x3f3f3f3f;int mp[405][405];int vis[405][405];int n,m;int data[4][2]={0,1,0,-1,1,0,-1,0};struct node{ int x,y,t; node(int _x,int _y,int _t) { x=_x,y=_y,t=_t; }};void bfs(){ int ans=0x3f3f3f3f; queue<node>q; node f(0,0,0); q.push(f); while(!q.empty()) { f=q.front(); q.pop(); if(vis[f.x][f.y])continue; vis[f.x][f.y]=1; if(mp[f.x][f.y]==inf) { ans=f.t; break; } for(int i=0;i<4;i++) { node s=f; s.x+=data[i][0],s.y+=data[i][1]; s.t+=1; if(s.x>n||s.y>n||s.y<0||s.x<0||mp[s.x][s.y]<=s.t) continue; q.push(s); } } if(ans==inf) printf("-1\n"); else printf("%d\n",ans);}int main(){ n=400; for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) mp[i][j]=inf; } int x,y,t; scanf("%d",&m); for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&t); if(mp[x][y]>t) mp[x][y]=t; for(int j=0;j<4;j++) { int dx=x+data[j][0],dy=y+data[j][1]; if(dx>n||dy>n||dy<0||dx<0||mp[dx][dy]<=t) continue; mp[dx][dy]=t; } } bfs();}
阅读全文
0 0
- POJ3669 Meteor Shower BFS
- poj3669 Meteor Shower BFS
- POJ3669 Meteor Shower(BFS)
- POJ3669 Meteor Shower 【BFS】
- POJ3669-Meteor Shower
- POJ3669 Meteor Shower
- 【poj3669】Meteor Shower 搜索
- POJ3669-Meteor Shower-BFS
- poj3669 Meteor Shower bfs
- Poj3669 meteor shower bfs
- poj3669-Meteor Shower
- POJ3669 Meteor Shower (BFS)
- POJ3669 Meteor Shower
- POJ3669 Meteor Shower(bfs)
- POJ3669-Meteor Shower(BFS)
- poj3669 Meteor Shower(bfs java)
- POJ3669 Meteor Shower 广度优先搜索
- 宽度优先搜索(BFS):POJ3669--Meteor Shower
- java进程cpu过高原因整理
- 算法设计与应用基础-第十三周&十四周
- ArrayList add()方法覆盖数据解决办法
- 四元素姿态解算 ---地磁计融合解读
- 进程保活之oom_adj级别查询
- poj3669-Meteor Shower
- TF/02_TensorFlow_Way/07 Combining_Everything_Together
- windows配置Redis环境【Redis · 1】
- GCD-两个网络请求同步问题_转载自马在路上大神
- 怎么样才能进入BAT公司的研发部门
- txt文件导入Mysql提示导入成功但是只有一条ID为0的无效数据
- contos 6.5安装PHP的curl扩展
- PLC编程序控制器的历史和展望
- 蚂蚁感冒问题暴力解决