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)
图的存储方法:邻接矩阵.邻接表 例如:有一个图如下所示(该图也作为程序的实例): 则上图用邻接矩阵可以表示为: 用邻接表可以表示如下: 邻接矩阵可以很容易的用二维数组表示,下面主要看看怎样构成邻接表: ...
随机推荐
- 【POJ】2236 Wireless Network
题目链接:http://poj.org/problem?id=2236 题意:给你n台计算机的坐标.d是可通信的最大距离.有两个操作. 1.O p 表示修复计算机p. 2.S p q表示询问pq是否能 ...
- 神经网络 (2)- Alexnet Training on MNIST
文章目录 Win10 Anaconda下配置tensorflow+jupyter notebook环境 AlexNet 识别MNIST Win10 Anaconda下配置tensorflow+jupy ...
- leetcode-157周赛-5214-最长定差子序列
题目描述: class Solution: def longestSubsequence(self, arr: List[int], difference: int) -> int: dp = ...
- [JZOJ3691] 【CF414E】Mashmokh's Designed tree
题目 题目大意 给你一棵树,接下来对这棵树进行三种操作: 1.询问两点之间的距离. 2.让某个点变为它原来的第\(h\)个祖先的最后一个儿子. 3.求\(dfs\)序中最后一个深度为\(k\)的点. ...
- 启动web项目,监听器、过滤器、拦截器启动顺序
启动顺序:监听器 > 过滤器 > 拦截器 记忆技巧:接到命令,监听电报,过滤敌情,拦截行动.
- bsgs+求数列通项——bzoj3122(进阶指南模板该进)
/* 已知递推数列 F[i]=a*F[i-1]+b (%c) 解方程F[x]=t an+1 = b*an + c an+1 + c/(b-1) = b(an + c/(b-1)) an+1 + c/( ...
- Keras+Yolo 目标检测
参考:https://www.cnblogs.com/tensorflownews/p/8922359.html Github:https://github.com/qqwweee/keras-yol ...
- Python 迭代器与生成器及装饰器
1.迭代器(Iterator) 迭代器是访问集合元素的一种方式.有下面特点: 1)每次调用__next__()方法只访问一个元素,而且不能后退,便于循环比较大的数据集合,节省内存:(当容器中没有可访问 ...
- day 70 Django基础五之django模型层(二)多表操作
Django基础五之django模型层(二)多表操作 本节目录 一 创建模型 二 添加表记录 三 基于对象的跨表查询 四 基于双下划线的跨表查询 五 聚合查询.分组查询.F查询和Q查询 六 ORM ...
- vue-select-lang
https://cli.vuejs.org/zh/guide/build-targets.html#%E5%BA%93 https://github.com/lipis/flag-icon-css