poj3669 之bfs解法
来源:互联网 发布:word2010表格数据求和 编辑:程序博客网 时间:2024/06/06 15:36
题意:流星雨空袭,求从原点出发到达安全路径的最小时间。
分析:果断bfs啊,但是这个地图真的难弄啊。
一开始我是在每次bfs的时候更新当前地图,可是忘了队列最多有300*300个点,妥妥的Time Limit Exceeded;
然后我弄了个三维数组,记录x,y和t,结果Memory Limit Exceeded,好羞耻啊。。。
最后只好在输入的时候就把地图处理好,然后直接bfs,这尼玛才过。
#include <cstdio>#include <queue>#include <cmath>using namespace std;#define INF 0x3f3f3f3fint n;int a,b,c;int row[5] = {0,0,1,-1,0};int col[5] = {1,-1,0,0,0};int unsafe[303][303];//是否到达安全地点int Time[303][303];//最先被砸到的时间int visit[303][303];struct point{int x,y,t;};queue<point>qu;point tem,con;int bfs(){while (!qu.empty()){tem = qu.front();qu.pop();if(!unsafe[tem.x][tem.y]) return tem.t;//已到达安全地区for (int i = 0; i < 4; i += 1){con.x = tem.x+row[i],con.y = tem.y+col[i],con.t = tem.t+1;if ((con.x >= 0 && con.y >= 0) && (con.t < Time[con.x][con.y]) && !visit[con.x][con.y]){qu.push(con);visit[con.x][con.y] = 1;}}}return -1;}int main(){for (int i = 0; i < 303; i += 1){for (int j = 0; j < 303; j += 1){unsafe[i][j] = 0;Time[i][j] = INF;visit[i][j] = 0;}}scanf("%d",&n);while (n--){scanf("%d%d%d",&a,&b,&c);if((a*a+b*b<=1) && c == 0){ printf("-1\n");return 0;} for (int i = 0; i < 5; i += 1){int nx = a+row[i],ny = b+col[i];if (nx >= 0 && ny >= 0){unsafe[nx][ny] = 1;Time[nx][ny] = min(Time[nx][ny],c);}}}tem.x = tem.y = tem.t = 0;qu.push(tem);visit[0][0] = 1;printf("%d\n",bfs());return 0;}
阅读全文
1 0
- poj3669 之bfs解法
- bfs--poj3669
- BFS POJ3669
- poj3669 BFS
- poj3669【bfs】
- poj3669 bfs
- poj3669(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——BFS经典
- POJ3669 Meteor Shower(bfs)
- POJ3669(BFS,障碍关联时间)
- (转)惊魂24小时!真实还原光大“乌龙指”事件,比小说还离奇
- APP中集成移动端车牌识别系统都能达到什么效果
- 数据结构实验一
- SpringBoot集成Redis,以及MybatisPlus分页、Mapper的使用(一)
- Unity简单利用屏幕坐标转换实现鼠标控制物体移动
- poj3669 之bfs解法
- spring笔记
- nvm和nodejs安装使用 (转)
- 多表查询内连接与外连接的区别;多表之间内连接;(常用)(只连接两个表都有效数据); 多表之间的外连接:(查询所有的内容); 多表内连接:(显示和隐式结果是一样的,得到的是交集的部分)
- android+postman
- maven管理jar包和传统方法管理jar的比较
- JUnit(二)高级之运行器_MD
- C#将DataGridView控件中的数据源转换为datatable内存表
- 2016CCPC东北地区大学生程序设计竞赛 H题 Basic Data Structure (模拟+双端队列)