题目链接:http://poj.org/problem?id=3669

很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_

写bfs或者dfs一定要记得对走过的地点进行记录,这题我本以为没必要记录了,结果就一直Memory Limit Exceeded

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#define ll long long
#define pi 3.1415927
#define inf 0x3f3f3f3f
using namespace std;
struct node {
int x,y,t;
};
int cost[][],x[]={,,,,-},y[]={,,-,,},mapp[][];
queue <node> p;
int bfs()
{
int i;
if(cost[][]==)
return -;
node aa,ex;
aa.t=; aa.x=; aa.y=;
p.push(aa);
while(!p.empty())
{
aa=p.front();
p.pop();
for(i=;i<;++i)
{
ex.t=aa.t+; ex.x=aa.x+x[i]; ex.y=aa.y+y[i];
if(ex.x>= && ex.y>= &&mapp[ex.x][ex.y]==)
if(cost[ex.x][ex.y]==-)
return ex.t;
else if (cost[ex.x][ex.y]>ex.t){
mapp[ex.x][ex.y]=; ///一开始没有记录走过的点就一直空间超限
p.push(ex);
}
}
}
return -;
}
int main ()
{
int n,m,i,t,j,k,jj,kk;
memset(cost,-,sizeof(cost));
scanf("%d",&n);
for(i=;i<n;++i)
{
scanf("%d %d %d",&j,&k,&m);
for(t=;t<;++t){
jj=j+x[t]; kk=k+y[t];
if(jj< || kk<)
continue;
if(cost[jj][kk]==-)
cost[jj][kk]=m;
else
cost[jj][kk]=min(cost[jj][kk],m);
}
}
mapp[][]=;
cout<<bfs()<<endl; return ;
}

poi 3669 meteor shower (bfs)的更多相关文章

  1. poj 3669 Meteor Shower(bfs)

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

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

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

  3. POJ 3669 Meteor Shower(流星雨)

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

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

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

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

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

  6. POJ 3369 Meteor Shower (BFS,水题)

    题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...

  7. POJ 3669 Meteor Shower【BFS】

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

  8. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

  9. 【算法导论】图的广度优先搜索遍历(BFS)

    图的存储方法:邻接矩阵.邻接表 例如:有一个图如下所示(该图也作为程序的实例): 则上图用邻接矩阵可以表示为: 用邻接表可以表示如下: 邻接矩阵可以很容易的用二维数组表示,下面主要看看怎样构成邻接表: ...

随机推荐

  1. mysql sql时间戳格式化语句

    FROM_UNIXTIME(c.lastUpdateTime/1000,'%Y-%c-%d %h:%i:%s' ) as updatetime; select c.roleid, r.username ...

  2. VBA文件对话框的应用(VBA打开文件、VBA选择文件、VBA选择文件夹)

    在VBA中经常要用到文件对话框来进行打开文件.选择文件或选择文件夹的操作.用Microsoft Office提供的文件对话框比较方便.用法如下Application.FileDialog(fileDi ...

  3. Android开发 多媒体提取器MediaExtractor详解_将一个视频文件分离视频与音频

    前言 此篇博客讲解MediaExtractor将一个视频文件分离视频与音频,如果你对MediaExtractor还没有一个笼统的概念建议先了解我的另一篇入门博客:https://www.cnblogs ...

  4. CSIC_716_20191104【流程控制语句】

    流程控制语句 if 语法结构 if 逻辑判断为真 : xxxxxx else: xxxxx while 语法结构  (continue.break) while 逻辑判断为真: xxxxxxx con ...

  5. 【luoguP4721】分治 FFT

    description 给定长度为\(n-1\)的数组\(g[1],g[2],..,g[n-1]\),求\(f[0],f[1],..,f[n-1]\),其中 \[f[i]=\sum_{j=1}^if[ ...

  6. flutter中的BuildContext

    https://www.jianshu.com/p/509b77b26b78

  7. json的dump和dumps的区别

    dumps是将dict转化成str格式,loads是将str转化成dict格式. dump和load也是类似的功能,只是与文件操作结合起来了. In [1]: import json In [2]: ...

  8. 区间dp及优化

    看了下感觉区间dp就是一种套路,直接上的板子代码就好了. 基础题ac代码:石子归并 #include<bits/stdc++.h> using namespace std; typedef ...

  9. 《DSP using MATLAB》Problem 8.38

    代码: function [wpLP, wsLP, alpha] = bp2lpfre(wpbp, wsbp) % Band-edge frequency conversion from bandpa ...

  10. ssm 框架整合 代码初步 maven配置

    pom.xml 配置<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <de ...