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 ...
随机推荐
- 关于c头文件的使用的小记录
在用visual studio实现数据结构上的一些结构与算法的时候,想在一个工程中建立几个文件,然后主文件可以使用其他文件的函数与变量(比如定义的结构体还有数据结构接口函数). 我们可以利用头文件来 ...
- CentOS系统里如何正确取消或者延长屏幕保护自动锁屏功能(图文详解)
不多说,直接上干货! 对于我这里想说的是,分别从CentOS6.X 和 CentOS7.X来谈及. 1. 问题:默认启动屏幕保护 问题描述: CentOS系统在用户闲置一段时间(默认为5分钟)后, ...
- 如何通过SecureCRT作为客户端连接Linux服务器
主机cmd ping虚拟机失败 打开计算机-管理-服务,找到所有以VMare开头的服务,右键点击启动即可,此时主机即可ping通虚拟机 可ping通之后,在主机cmd窗口输入 ssh root@192 ...
- 【原】无脑操作:Eclipse + Maven + jFinal + MariaDB 环境搭建
一.开发环境 1.windows 7 企业版 2.Eclipse IDE for Enterprise Java Developers Version: 2019-03 (4.11.0) 3.JDK ...
- AJPFX总结IO流中的缓冲思想
缓冲思想 (因为内存的运算速度要远大于硬盘的原酸速度,所以只要降低硬盘的读写次数,就可以提高效率) 1. 字节流一次读写一个数组的速度明显比一次读写一个字节的速度快很多, 2. 这是加 ...
- Android开发中使用数据库时出现java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
最近在开发一个 App 的时候用到了数据库,可是在使用数据库的时候就出现了一些问题,在我查询表中的一些信息时出现了一下问题: Caused by: java.lang.IllegalStateExce ...
- ESSENTIALS OF PROGRAMMING LANGUAGES (THIRD EDITION) :编程语言的本质 —— (一)
# Foreword> # 序 This book brings you face-to-face with the most fundamental idea in computer prog ...
- postgresql update from
1,update from 关联表的更新 update table a set name=b.name from table B b where a.id=b.id; update test ...
- windows下管理ubuntu服务器以及切换root身份
远程连接Linux云服务器-命令行模式 1.远程连接工具.目前Linux远程连接工具有很多种,您可以选择顺手的工具使用.下面使用的是名为Putty(putty.rar)的Linux远程连接工具.该工具 ...
- swift 多态函数方式
1.v-table: class 2.WitnessTable protocol 3.消息派发. @objc dynamic