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听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...
随机推荐
- (转)Centos7下杀毒软件clamav的安装和使用
本文转载自:https://www.cnblogs.com/bingo1024/p/9018212.html#_label1_0 目录 一.yum安装 二.编译安装 2.1:下载软件包 2.2:创建c ...
- Linux性能优化从入门到实战:17 网络篇:网络基础
网络模型 为了解决网络互联中异构设备的兼容性问题,并解耦复杂的网络包处理流程,国际标准化组织制定了开放式系统互联通信参考模型(Open System Interconnection Reference ...
- 理解uboot过程中的优秀博客
To_run_away的博客 https://blog.csdn.net/qq_16777851/column/info/28098/5 加了微信好友,公众号也有文章. Camus https://c ...
- [sqlmap源码阅读] 数据库识别
通过网页返回的数据库错误信息识别网站所有数据库类型,用到的正则表达式及支持识别的数据库类型,这些信息以xml文件的形式存在,使用 sax 解析xml.
- python数据分析第二版:pandas
一:pandas 两种数据结构:series和dataframe series:索引(索引自动生成)和标签(人为定义)组成---返回一个对象 obj = pd.Series([1,2,3,4]) ob ...
- man fdisk
FDISK(8) Linux Programmer?. Manual/Linux程序手册 FDISK(8) NAME/名称 fdisk - Partition ta ...
- 【leetcode】712. Minimum ASCII Delete Sum for Two Strings
题目如下: 解题思路:本题和[leetcode]583. Delete Operation for Two Strings 类似,区别在于word1[i] != word2[j]的时候,是删除word ...
- Ckeditor IE下粘贴word中图片问题
自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...
- HY 的惩罚 (Trie 树,博弈论)
[问题描述] hy 抄题解又被老师抓住了,现在老师把他叫到了办公室. 老师要 hy 和他玩一个游 戏.如果 hy 输了,老师就要把他开除信息组; 游戏分为 k 轮.在游戏开始之前,老师会将 n 个由英 ...
- easyui的datagrid里getSelections只能获取一行值???
使用getSelections只能获取到一行的值,检查了半天是因为idField属性值写错,更正之后ok. 解决办法二:改为使用getChecked,idField写错无影响, 注: getSelec ...