http://poj.org/problem?id=3669

注意理解题意:有m颗行星将会落在方格中(第一象限),第i颗行星在ti时间会摧毁(xi,yi)这个点和四周相邻的点,一个人开始在原点,然后只能在第一象限内行走,每单位时间移动一格,只能移动到当前未摧毁的点,问多少时间能到达安全地方。

开始题意理解错了,没有明白每一颗行星最多摧毁5个点,我们可以预处理出被行星摧毁的点,然后用bfs搜索。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
//#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define maxn 1000000000
#define N 1010
using namespace std; int dir[][]={-,,,,,,,-,,};
int vis[][];
struct node
{
int x,y,time;
}; int bfs()
{
if(vis[][]==-) return ;
node p;
p.x=p.y=p.time=;
queue<node>que;
que.push(p);
while(que.size())
{
node q=que.front();
que.pop();
for(int i=;i<;i++)
{
p=q;
p.x=q.x+dir[i][];
p.y=q.y+dir[i][];
p.time++;
if(p.x<||p.y<) continue; //出界了
if(vis[p.x][p.y]==-) return p.time; //到达安全地方
if(p.time<vis[p.x][p.y]) //当前这个点还未摧毁
{
vis[p.x][p.y]=p.time; //必须赋值,不然会超时,这样可以防止往回走的情况,节省不必要的搜索
que.push(p);
}
}
}
return -;
}
int main()
{
//freopen("a.txt","r",stdin);
int m,x,y,t;
scanf("%d",&m);
memset(vis,-,sizeof(vis));
while(m--)
{
scanf("%d%d%d",&x,&y,&t);
for(int i=;i<;i++)
{
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx>=&&yy>=) //预处理所有被摧毁的点,并赋值为被摧毁的最小时间。
{
if(vis[xx][yy]==-) vis[xx][yy]=t;
else vis[xx][yy]=min(t,vis[xx][yy]);
}
}
}
if(vis[][]==) printf("-1\n");
else printf("%d\n",bfs());
return ;
}

POJ-3669 Meteor Shower(bfs)的更多相关文章

  1. POJ 3669 Meteor Shower BFS求最小时间

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31358   Accepted: 8064 De ...

  2. POJ 3669 Meteor Shower BFS 水~

    http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...

  3. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  4. POJ 3669 Meteor Shower【BFS】

    POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...

  5. poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  6. POJ 3669 Meteor Shower (BFS+预处理)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  7. 题解报告:poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  8. poj 3669 Meteor Shower

                                                                                                      Me ...

  9. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  10. poj3669 Meteor Shower(BFS)

    题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...

随机推荐

  1. 【转载】Sencha Touch 提高篇 组件选择器

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:威老     原文地址:http://www.cnblogs.com/weil ...

  2. 【转】Basic C# OOP Concept

    This Article will explain a very simple way to understand the basic C# OOP Concept Download ShanuBas ...

  3. 【DP】permu

    permu [Description] 给定两个1~N的全排列A,B.有两个指针q和p,一开始q.p都为0,可执行以下三种操作: 1.q+1:2.p+1:3.q+1且p+1(Aq+1≠Bp+1时才可以 ...

  4. 【转载】MySQL索引原理及慢查询优化

    原文链接:美团点评技术团队:http://tech.meituan.com/mysql-index.html MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型 ...

  5. 用fscanf()从文件取数据时,如何判断文件结束

    例子:从键盘输入若干行字符(每行长度不等),输入后把它们存储到一磁盘文件中.再从该文件中读入这些数据,将其中小写字母转换成大写字母后再显示屏上输出. 有两种方法 1.使用feof()函数 #inclu ...

  6. Ckeditor 中一些核心的对象的作用

    1.CKEditor CKEditor对象用于掌管全局,他是一个单例对象,管理着所有实例化了的编辑框. 通过replace方法创建编辑框实例. 2.CKEditor.editor 表示一个编辑框实例, ...

  7. Sqli-labs less 38

    Less-38 学习了关于stacked injection的相关知识,我们在本关可以得到直接的运用. 在执行select时的sql语句为:SELECT * FROM users WHERE id=' ...

  8. php弱类型

    此处写ctf中遇到的==和md5值为0e**的应用. 数组和字符的===   ==

  9. JavaScript js 精确、保留小数方法

    //保留两位小数 //功能:将浮点数四舍五入,取小数点后2位 function toDecimal(x) { var f = parseFloat(x); if (isNaN(f)) { return ...

  10. login shell 和 non-login shell 的区别

    介绍之前先思考一个问题:有时我们通过su命令切换用户后,却发现并没有进入该用户的shell环境.这是为什么? login shell:取得bash时需要完整的登录流程.就是说通过输入账号和密码登录系统 ...