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 ...
随机推荐
- 支付宝添加scheme的方法
点击项目名称,点击“Info”选项卡,在“URL Types”选项中,点击“+”,在“URL Schemes”中输入“myAlipay”.“myAlipay”来自于文件“APViewControlle ...
- e.Row.RowType == DataControlRowType.DataRow详解(转)
代码语句如下: protected void OnRowCreate(object sender, GridViewRowEventArgs e) { if (e.Row.RowT ...
- 移动端 H5 拍照 从手机选择图片,移动端预览,图片压缩,图片预览,再上传服务器
前言:最近公司的项目在做全网营销,要做非微信浏览器的wap 站 的改版,其中涉及到的一点技术就是采用H5 选择手机相册中的图片,或者拍照,再将获取的图片进行压缩之后上传. 这个功能模块主要有这5点比较 ...
- MYSQL 查询方法 统计查询 链接查询 子查询
mysql表格查询方法: 查询: 1.简单查询 select * from Info --查所有数据select Code,Name from Info --查指定列的数据select Code as ...
- ASP.NET Excel下载方法一览
方法一 通过GridView(简评:方法比较简单,但是只适合生成格式简单的Excel,且无法保留VBA代码),页面无刷新 aspx.cs部分 using System; using System.Co ...
- redis-cli 工具--raw参数的作用
最近阅读了以redis官网关于--raw参数的解释,其功能有两个: 1.按数据原有格式打印数据,不展示额外的类型信息 例如:使用命令发送方式(redis在使用时有命令发送方式和交互方式两种)创建一个k ...
- 本地连接批处理修改IP
例子: 本地连接修改IP netsh interface ip delete dns "本地连接" addr=allnetsh interface ip add dns " ...
- 【译】x86程序员手册36-9.9异常汇总
9.9 Exception Summary 异常汇总 Table 9-6 summarizes the exceptions recognized by the 386. Table 9-6. Exc ...
- 循环和递归的区别(以前以为递归就是for循环!错的!)
这里直接上代码!!!! //代码1:(for循环实现的代码) void main() { ; ; i<;i++) { n++; } printf("%d",n); } //代 ...
- OpenMP用法大全
OpenMP基本概念OpenMP是一种用于共享内存并行系统的多线程程序设计方案,支持的编程语言包括C.C++和Fortran.OpenMP提供了对并行算法的高层抽象描述,特别适合在多核CPU机器上的并 ...