POJ3669 Meteor Shower
http://poj.org/problem?id=3669
类似于迷宫的一道题 但是并没有 给出迷宫具体什么样
但是题目已说在坐标轴的第一象限
然后障碍就是 流星雨所砸范围
安全位置:永远不会发生危险的地方
那就变成一道纯广搜的题目了
具体思路:
预处理 将有危险的地方 标注为发生危险的时间(取最小!!!!)
其余地方取为-1(因为可能0时刻就发生危险了)
然后开始搜索
细节细节:
wrong1:超时 没有放访问数组visit一个地方是不需要重复访问的 不仅增加了步数搜索的时间 还降低了逃生的可能性 是无效操作
wrong2:将danger数组初始化为0 以为0就是安全的 但是流行可以0时刻坠落
wrong3:danger赋值 周围范围取最小 但是在输入坠落处时 忘记加判断
卡了一个晚上 。。。。。
#include <iostream>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <string.h> using namespace std; const int INF = INT_MAX;
int M,k;
struct Meteor
{
int x,y,t;
};
queue<Meteor> que;
typedef pair<int,int> P;
int danger[][];
bool visit[][];
int min_time = INF;
int d[][] = { {, }, {, }, {-, }, {, -} }; bool check(int x, int y)//检查是否越界 保http://poj.org/problem?id=3009证在第一象限
{
if (x < || y < ) return false;
return true;
} void bfs()
{
Meteor node,temp;
node.x = ;
node.y = ;
node.t = ;
visit[][] = true;
que.push(node);
while (!que.empty())
{
node = que.front();
que.pop();
//检查是否到达安全区
if (danger[node.x][node.y] == -)//如果到达安全区
{
min_time = min(min_time, node.t);
continue;
}
//没到安全区 那么查找周围可以走的点
for (int i = ; i <; i++)
{
if (check(node.x+d[i][], node.y+d[i][]))//没有越界
{
if (visit[node.x+d[i][]][node.y+d[i][]]) continue;//不走重复路 否则TLE
if (danger[node.x+d[i][]][node.y+d[i][]] == - || danger[node.x+d[i][]][node.y+d[i][]] > node.t + )//如果这个点可以走
{
temp.x = node.x + d[i][];
temp.y = node.y + d[i][];
temp.t = node.t + ;
que.push(temp);
visit[temp.x][temp.y] = true;
}
}
}
}
}
int main()
{
int tx, ty, tt;
freopen("in.txt", "r", stdin);
while (~scanf("%d", &M) )
{
min_time = INF;
memset(danger, -, sizeof(danger));
memset(visit, false, sizeof(visit));
for (int i = ; i < M; i++)
{
scanf("%d%d%d", &tx, &ty, &tt);
if (danger[tx][ty] < || danger[tx][ty] > tt)//82行知道取最小 直接输入的时候却忘记判断了Oh !
danger[tx][ty] = tt;
for (int j = ; j < ; j++)
{
if (check(tx+d[j][],ty+d[j][]))//如果为没有越界,周围四个点也是被摧毁的地区
{
danger[tx+d[j][]][ty+d[j][]] = danger[tx+d[j][]][ty+d[j][]] == - ? tt : min(tt, danger[tx+d[j][]][ty+d[j][]]);
}
}
}
bfs();
if (min_time == INF)
printf("-1\n");
else printf("%d\n", min_time);
}
return ;
}
POJ3669 Meteor Shower的更多相关文章
- poj3669 Meteor Shower(BFS)
题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...
- POJ3669(Meteor Shower)(bfs求最短路)
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12642 Accepted: 3414 De ...
- poj3669 Meteor Shower(预处理+bfs)
https://vjudge.net/problem/POJ-3669 先给地图a[][]预处理每个位置被砸的最小时间.然后再bfs. 纯bfs,还被cin卡了下时间.. #include<io ...
- POJ-3669 Meteor Shower(bfs)
http://poj.org/problem?id=3669 注意理解题意:有m颗行星将会落在方格中(第一象限),第i颗行星在ti时间会摧毁(xi,yi)这个点和四周相邻的点,一个人开始在原点,然后只 ...
- poj3669 Meteor Shower (宽度优先搜索)
Description - 题目描述 Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平面坐标系的原点放牧,打算在群星 ...
- 【POJ - 3669】Meteor Shower(bfs)
-->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- poj 3669 Meteor Shower
Me ...
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 904 Solved: 393 ...
随机推荐
- LN : leetcode 343 Integer Break
lc 343 Integer Break 343 Integer Break Given a positive integer n, break it into the sum of at least ...
- 从源码对比DefaultServeMux 与 gorilla/mux
从源码对比DefaultServeMux 与 gorilla/mux DefaultServeMux Golang自带的net/http库中包含了DefaultServeMux方法,以此可以搭建一个稳 ...
- [Luogu2901][USACO08MAR]牛慢跑Cow Jogging Astar K短路
题目链接:https://daniu.luogu.org/problem/show?pid=2901 Astar的方程$f(n)=g(n)+h(n)$,在这道题中我们可以反向最短路处理出$h(n)$的 ...
- 【Python】第一个爬虫
import urllib.request import re class DownPic: def __init__(self,url,re_str): self.url = url self.re ...
- iOS Programming View Controllers 视图控制器
iOS Programming View Controllers 视图控制器 1.1 A view controller is an instance of a subclass of UIVi ...
- 【译】x86程序员手册40-10.5初始化的例子
10.5 Initialization Example初始化的例子 译注:本来想把这个例子全部注释完,但由于对intel汇编实不熟悉,有太多的伪指令,本人也是免强看懂,所以就不再做翻译了. $TITL ...
- cp - 复制文件和目录
总览 cp [选项] 文件路径 cp [选项] 文件...目录 POSIX 选项: [-fipRr] GNU 参数(最短形式): [-abdfilprsuvxPR] [-S SUFFIX] [-V { ...
- chroot - 以 特定 根 目录 运行 命令 或者 交互式 shell
总览 (SYNOPSIS) chroot [OPTION] NEWROOT [COMMAND...] chroot OPTION 描述 (DESCRIPTION) 以 NEWROOT 为 根 目录 运 ...
- 时钟周期 VS 机器周期
时钟周期vs机器周期 Clock cycle The speed of a computer processor, or CPU, is determined by the clock cycle, ...
- java解决动态的锁顺序死锁的方案
直接上代码 public class Test3 { public static Object fromAccount = new String("1"); public stat ...