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 ...
随机推荐
- TDB 12c : Transportable Database
转 http://oracleinaction.com/12c-transportable-database/
- 459 Repeated Substring Pattern 重复的子字符串
给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成.给定的字符串只含有小写英文字母,并且长度不超过10000.示例 1:输入: "abab"输出: True解释: 可由 ...
- 转】RMySQL数据库编程指南
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/2/ 感谢! Posted: Sep 24, 2013 Ta ...
- for循环的两种写法哪个快
结果如下: 其实工作中,也没有这么多数据需要遍历,基本上用foreach
- 掌握Spark机器学习库-07.6-线性回归实现房价预测
数据集 house.csv 数据概览 代码 package org.apache.spark.examples.examplesforml import org.apache.spark.ml.fea ...
- Python学习 Day 3 字符串 编码 list tuple 循环 dict set
字符串和编码 字符 ASCII Unicode UTF-8 A 1000001 00000000 01000001 1000001 中 x 01001110 00101101 11100100 101 ...
- R Programming week2 Control Structures
Control Structures Control structures in R allow you to control the flow of execution of the program ...
- [经典面试题]包含T全部元素的最小子窗口
题目描述 给定一个包含一系列字符的集合T和字符串S,请在字符串S中找到一个最小的窗口,这个窗口中必须包含T中的所有字符. 例如, S = "ADOBECODEBANC" T ...
- 【C++】模板简述(四):模板为什么不支持分离编译?
上文简述了类模板相关功能,本文主要简述为什么模板不支持分离编译? 在C++中,为了一个项目的规范,我们通常把代码归为三类:声明文件.实现文件.测试文件. 比如,我要用C++实现一个链表,那么就会创建这 ...
- jboss中JVM监控
1)打开 http://server-name-or-ip/jmx-console/HtmlAdaptor2)在 jboss.system 节点找到 type=ServerInfo ,点击进入3)找到 ...