题目链接: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. nio读取文件,输出文件

    io流的一种: package com.cxy.ssp.Automic; import java.io.FileOutputStream; import java.io.IOException; im ...

  2. Unity开发一些实用的提高效率的技巧

    该文章参考总结自Unity微信官方 原文: Unity小技巧介绍 1 如果编辑器意外崩溃了,但场景未保存,这时可以打开工程目录,找到/Temp/_Backupscenes/文件夹,可以看到有后缀名为. ...

  3. openwrt xfrp移植

    对开源软件表示支持 https://github.com/KunTengRom/xfrp 上传编译,选择 cp .config xxx make 刷机 客户端配置文件: /tmp/etc# cat x ...

  4. java String,StringBuilder和StringBuffer类的区别

    对String而言: String是只读字符串,所引用的字符串不能被改变,一经定义,无法再增删改. String 定义的字符串保存在常量池里面,进行+操作时不能直接在原有基础上拼接. 每次+操作 : ...

  5. jquery实现文字由下到上循环滚动的实例代码

    <div id="oDiv"> <ul id="oUl"> <li>第1个li元素</li> <li> ...

  6. 【JZOJ6274】梦境

    description analysis 其实可以贪心 先把区间按左端点排序,转折点也排序 扫一次转折点,把所有左端点在当前点左边的区间丢进优先队列里 按照贪心策略,对于某个转折点,一定选择右端点离它 ...

  7. Delphi利用Windows GDI实现文字倾斜

    Delphi利用Windows GDI实现文字倾斜 摘要 Delphi利用Windows GDI实现文字倾斜 procedure TForm1.FormPaint(Sender: TObject);v ...

  8. c#上传下载ftp(支持断点续传)

    using System;using System.Net;using System.IO;using System.Text;using System.Net.Sockets;namespace f ...

  9. PHP实现对短信验证码发送次数的限制

    http://www.jb51.net/article/94878.htm 对用户获取短信验证码的手机号.ip.和浏览器(使用唯一标识)进行限制.本文介绍的方法是对用户每天只能通过同一浏览器或同一ip ...

  10. CCPC 2019 网络赛 HDU huntian oy (杜教筛)

    1005 huntian oy (HDU 6706) 题意: 令,有T次询问,求 f(n, a, b). 其中 T = 10^4,1 <= n,a,b <= 1e9,保证每次 a,b互质. ...