这道题是下流星,流星会下到上下左右中的位置,而且有时间的,要你求出最短到达安全位置的时间。

这道题要注意边界是可以超过300的

#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
typedef pair<int,int> P;
#define INF 0x3f3f3f3f
queue<P>q;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int d[306][306];
int dd[306][306];
int gx,gy;
int flag=0;
int dfs()
{
memset(dd,INF,sizeof(dd));
q.push(P(0,0));
dd[0][0]=0;
while(q.size())
{
P p=q.front();q.pop();
if(d[p.first][p.second]==INF){
gx=p.first;
gy=p.second;
flag=1;
break;
}
for(int i=0;i<4;i++)
{
int nx=p.first+dx[i],ny=p.second+dy[i];
if(0<=nx&&nx<=305&&0<=ny&&ny<=305&&dd[nx][ny]==INF)
{//printf("%d %d %d\n",nx,ny,d[nx][ny]);
dd[nx][ny]=dd[p.first][p.second]+1;
if(dd[nx][ny]<d[nx][ny])
q.push(P(nx,ny));
}
}
}
if(flag)
return dd[gx][gy];
else return -1;
}
int main()
{
int m,x,y,t,n;
scanf("%d",&n);
memset(d,INF,sizeof(d));
for(int i=0;i<n;i++)
{
scanf("%d %d %d",&x,&y,&t);
d[x][y]=min(d[x][y],t);
for(int i=0;i<4;i++)
{
int nx=x+dx[i],ny=y+dy[i];
if(0<=nx&&nx<=305&&0<=ny&&ny<=305)
d[nx][ny]=min(d[nx][ny],t);
}
}
int res=dfs();
printf("%d\n",res);
}

poj Meteor Shower的更多相关文章

  1. poj Meteor Shower - 搜索

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16313   Accepted: 4291 Description Bess ...

  2. POJ 3669 Meteor Shower(流星雨)

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

  3. poj 3669 Meteor Shower

                                                                                                      Me ...

  4. poj 3669 Meteor Shower(bfs)

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

  5. Meteor Shower(POJ 3669)

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12816   Accepted: 3451 De ...

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

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

  7. Meteor Shower POJ - 3669 (bfs+优先队列)

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26455   Accepted: 6856 De ...

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

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

  9. 【POJ - 3669】Meteor Shower(bfs)

    -->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...

随机推荐

  1. mysql 导出表中数据为excel的xls格式文件

    需求: 利用mysql客户端导出数据库中数据,以便进行分析,统计. 解决命令: 在windos命令行(linux同理)下,用如下命令即可: mysql -hlocalhost -uroot -ppas ...

  2. Jquery异步上传文件

    我想通过jQuery异步上传文件,这是我的HTML: 1 2 3 <span>File</span> <input type="file" id=&q ...

  3. Robomongo可视化命令

    ## 更新命令示例 db.getCollection('collection_name').update(    {'_id':ObjectId('id string')},     {$set:{' ...

  4. BZOJ 5046 分糖果游戏

    网页崩溃了 心态也崩溃了 MD劳资写了那么多 题意: 有a,b两个人分糖,每个人都有一个能量值.每个人每一轮可以选择进行两种操作: 1.取走最左边的糖果,补充相应的能量值并获取相应的美味度. 2.跳过 ...

  5. 企业级监控软件Zabbix搭建部署之zabbix在WEB页面中的配置

    企业级监控软件zabbix搭建部署之zabbix在WEB页面中的配置 企业级监控软件zabbix搭建部署之zabbix在WEB页面中的配置 关于安装请看 http://www.linuxidc.com ...

  6. dede标签大全

    想必很多人对后台不熟悉,并且觉得很难.其实不难,只是你们没有找到合适的方法学习而已!只有找到一个合适的学习方法,不管做什么事情,我想都很容易.学习讲究的是效率,而效率又是由思路决定的.就拿网页制作来说 ...

  7. Linux内核设计与实现 总结笔记(第六章)内核数据结构

    内核数据结构 Linux内核实现了这些通用数据结构,而且提倡大家在开发时重用. 内核开发者应该尽可能地使用这些数据结构,而不要自作主张的山寨方法. 通用的数据结构有以下几种:链表.队列.映射和二叉树 ...

  8. android开发里跳过的坑——GridView使用Glide加载图片不显示

    用grideview显示本地图片列表,用了Glide加载框架,具体调用如下: Glide.with(mContext).load(Uri.fromFile(file)).into(imageView) ...

  9. Python_013(面向对象概念)

    一.面向对象 1.面向对象几个概念问题: a:类:具有相同属性和技能的一类事物.用代码表示就是,我类里面有一些静态变量和方法是大家共有的; b:对象:具体的类的表现.在代码中就是,调用类的方法或变量传 ...

  10. 【2019 Multi-University Training Contest 8】

    01: 02: 03:https://www.cnblogs.com/myx12345/p/11655876.html 04: 05: 06:https://www.cnblogs.com/myx12 ...