poi 3669 meteor shower (bfs)
题目链接: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)的更多相关文章
- 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)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- 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听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...
- POJ 3369 Meteor Shower (BFS,水题)
题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...
- POJ 3669 Meteor Shower【BFS】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- 深搜(DFS)广搜(BFS)详解
图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...
- 【算法导论】图的广度优先搜索遍历(BFS)
图的存储方法:邻接矩阵.邻接表 例如:有一个图如下所示(该图也作为程序的实例): 则上图用邻接矩阵可以表示为: 用邻接表可以表示如下: 邻接矩阵可以很容易的用二维数组表示,下面主要看看怎样构成邻接表: ...
随机推荐
- **JLink Warning: Mis-aligned memory write: Address: 0x20000000, NumBytes: 2, Alignment: 2 (Halfword-aligned)
网上也有同学遇到这个问题,http://www.openedv.com/thread-113049-1-3.html 根据他的经验我也重新安装了Jlink驱动: 顺便注意Dialog DLL:TARM ...
- 利用msbuild白名单执行shellcode
x64:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe x32:C:\Windows\Microsoft.NET\Framewo ...
- H5点击拨打电话,发短信
phone(){ window.location.href = 'tel:123123'// 拨打电话 window.location.href = 'sms:123123'// 发短信 }
- 【JZOJ6367】工厂(factory)
description 大神 wyp 开了家工厂,工厂有 n 个工人和 p 条流水线. 工厂的工人都是睡神,因此第 i 个工人只会在 si 至 ti 时刻才会工作. 每个工人都会被分派到一条流水线上, ...
- react 实现类似vue中的<keep-alive>的功能,并解决antd-mobile切换回来时的空白
在移动端的spa页面中,只要使用到了路由就很有必要使用到状态保存的功能,这样才能保证在页面进行切换的时候,让用户可以看到刚才滑动的地方,让用户的体验更加友好.这儿我找到了react-router-ca ...
- 树形dp——cf1010D
一个点的改变如果对根节点的值不会造成任何影响,那么这个点的所有子节点的改变也不会对根节点造成影响 因为每次只改一个叶子节点,也就是一条到根的路径,可以先预处理出初始情况下的每个结点的值 分别讨论根节点 ...
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- 动态调整Log4j日志级别
log4j2.xml配置文件中支持配置monitorInterval参数,检测到配置改变后重新加载,达到动态调整日志级别的效果. 故调整日志级别无须手动重启服务. log4j2.xml配置文件示意: ...
- 6_3.springboot2.x数据整合Mybatis(注解和非注解)
1.配置文件 pom.xml 导入mybatis提供的启动器 <dependency> <groupId>org.mybatis.spring.boot</groupId ...
- CentOS7-Minimal安装MySQL服务
CentOS7默认安装的是Mariadb而不是mysql,而Mariadb是mysql的一个分支, 安装mysql会覆盖Mariadb 一.下载MySQL官方的 Yum Repository [roo ...