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

这道题要注意边界是可以超过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. popen, pclose - process I/O

    SYNOPSIS #include <stdio.h> FILE *popen(const char *command, const char *type); int pclose(FIL ...

  2. Could not resolve all files for configuration ':app:debugCompileClasspath'.解决方案

    异常如下: Error:FAILURE: Build failed with an exception. * What went wrong:Could not resolve all files f ...

  3. Sumdiv(约数和问题)

    题目地址 看到这题的题解,大佬都说是小学奥数,蔡得我不敢鸡声. 求 \(a^b\) 所有的约数之和 mod \(9901\) \((1<=a,b<=5*10^7)\) 题解 做这道题,我还 ...

  4. [python 学习] 使用 xml.etree.ElementTree 模块处理 XML

    ---恢复内容开始--- 导入数据(读文件和读字符串) 本地文件 country_data.xml <?xml version="1.0"?> <data> ...

  5. 揭示编译器API

    编译器管道功能区 .NET编译器平台(“Roslyn”)通过提供一个API层,是一个传统编译器管道镜像,向你这样的消费者揭示了C#和Visual Basic编译器的代码分析. 这条管道的每一部分,现在 ...

  6. 牛客ACM赛 B [小a的旅行计划 ]

    链接 B 小a的旅行计划 把\(n\)个数中选任意数分成\(a,b\)两个集合,集合无区别,要求不包含且有交,求方案数.\(n\leq 10^{13}\) 首先讨论\(a,b\)并集是否为全集: 若是 ...

  7. Linux g++ 编译添加 pthread

    If you are going to compile a C program with pthread.h in LINUX using GCC or G++ you will have to us ...

  8. SQL Server性能调优--索引

    序言 索引的概念 索引是什么 数据库中的索引类似于一本书的目录,在一本书中使用目录可以快速找到你想要的信息,而不需要读完全书.在数据库中,数据库程序使用索引可以快速查询到表中的数据,而不必扫描整个表. ...

  9. 夯实Java基础系列7:Java 代码块和执行顺序

    本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial 喜欢的话麻烦点下 ...

  10. (转)利用VMware克隆虚拟机需要注意的问题

    第一步:关闭当前机器 第二步:在VMware中右键要克隆的机器 选择管理-->克隆 第三步:启动新克隆的虚拟机 修改主机名 如 hostname  slave2 第四步:修改克隆的虚拟机的ip地 ...