poj Meteor Shower
这道题是下流星,流星会下到上下左右中的位置,而且有时间的,要你求出最短到达安全位置的时间。
这道题要注意边界是可以超过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的更多相关文章
- poj Meteor Shower - 搜索
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16313 Accepted: 4291 Description Bess ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- poj 3669 Meteor Shower
Me ...
- poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- Meteor Shower(POJ 3669)
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12816 Accepted: 3451 De ...
- POJ 3669 Meteor Shower (BFS+预处理)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- Meteor Shower POJ - 3669 (bfs+优先队列)
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26455 Accepted: 6856 De ...
- 题解报告:poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- 【POJ - 3669】Meteor Shower(bfs)
-->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...
随机推荐
- RSA加密原理与秘钥、公钥生成
RSA加密(非对称加密) RSA公开密钥密码体制.所谓的公开密钥密码体制就是使用不同的加密密钥与解密密钥,是一种“由已知加密密钥推导出解密密钥在计算上是不可行的”密码体制.(不可逆向运算的加密方法) ...
- sqli(7)
前言 第7关 导出文件GET字符型注入 步骤OK,但是就是不能写入文件,不知是文件夹的问题还是自己操作的问题.但是确实,没有导入成功. 1. 查看闭合,看源码,发现闭合是((‘ ’)): 2.查看所在 ...
- PTA 错题记录
程设期中考, 记录一下曾经做错的选择填空. 1. 2. 3. 4. 5. 6.
- PCB项目 X1 STC12C5A60S2-LQPF48
单片机控制系统双层板STC51 简介: STC12C5A60S2主芯片,12MHz主频 12V电源输入,12/5/3V电源输出 4路0~12V可调10位ADC输入 4路1A大电流达林顿输出 4路INT ...
- 关于<label>的for属性的简单探索
在freecodecamp上HTML教程的Create a Set of Radio Buttons这一节中,看到这样一段话, It is considered best practice to se ...
- flask之显示当地时间
一:在网页上显示时间 flask-moment 程序扩展可以实现 pip install flask-moment # 未完待续
- 启动模式:uefi, legacy,以及GRUB命令使用
机器启动模式:uefi, legacy 设置入口:BIOS:boot mode 磁盘分区表格式: gpt uefi所使用(此种模式下,grub只能识别gpt格式的boot引导项) mbr legacy ...
- RPC的解释以及RPC和Restful、RPC和RMI的区别
如何科学的解释RPC 说起RPC,就不能不提到分布式,这个促使RPC诞生的领域. 假设你有一个计算器接口,Calculator,以及它的实现类CalculatorImpl,那么在系统还是单体应用时,你 ...
- Django的使用一
Django是一个由Python写成的Web应用框架,是 Python 社区的两大最受欢迎的 Web 框架之一(另一个是 Flask). Django的主要目的是简便.快速的开发数据库驱动的网站. 1 ...
- 怎么实现web端上传超大文件
1.介绍enctype enctype 属性规定发送到服务器之前应该如何对表单数据进行编码. enctype作用是告知服务器请求正文的MIME类型(请求消息头content-type的作用一样) 1. ...