POJ 3669 Meteor Shower BFS 水~
http://poj.org/problem?id=3669
题目大意:
一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达安全地点的最小时间,若无解输出-1
思路:
好吧,我最近都在做水题。
输入的时候更新地图,每个点取最小的被破坏的时间,然后进行BFS,在BFS途中,如果当前时间>=被破坏的,那么就代表不能进入。
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=300+10;
const int dx[]={1,-1,0,0,0};
const int dy[]={0,0,1,-1,0};
int map[MAXN][MAXN];
bool vis[MAXN][MAXN];
void update(int x,int y,int t)
{
if(x<0||y<0) return;
if(map[x][y] !=-1 && map[x][y]<=t) return;
map[x][y]=t;
} struct state
{
int x,y,t;
state(int x=0,int y=0,int t=0):x(x),y(y),t(t){}
}; int bfs()
{
memset(vis,0,sizeof(vis));
queue<state> q;
q.push(state(0,0,0));
while(!q.empty())
{
state cur=q.front();
q.pop();
for(int i=0;i<4;i++)
{
int nx=cur.x+dx[i];
int ny=cur.y+dy[i];
if( nx<0 || ny<0 ) continue;
if(map[nx][ny]==-1) return cur.t+1;
int nt=cur.t+1;
if( vis[nx][ny] || nt>=map[nx][ny]) continue;
q.push(state(nx,ny,nt));
vis[nx][ny]=true;
}
}
return -1;
}
int main()
{
int m;
while(~scanf("%d",&m))
{
memset(map,-1,sizeof(map));
for(int i=0;i<m;i++)
{
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
for(int i=0;i<5;i++)
update(x+dx[i],y+dy[i],t);
}
printf("%d\n",bfs());
}
return 0;
}
POJ 3669 Meteor Shower BFS 水~的更多相关文章
- POJ 3669 Meteor Shower BFS求最小时间
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31358 Accepted: 8064 De ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- POJ 3669 Meteor Shower【BFS】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- 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(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- poj 3669 Meteor Shower
Me ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- poj3669 Meteor Shower(BFS)
题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...
随机推荐
- RocketMQ 就是耗内存
http://blog.csdn.net/loongshawn/article/details/51086876 https://rocketmq.incubator.apache.org/docs/ ...
- CODEVS——T1052 地鼠游戏
http://codevs.cn/problem/1052/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 D ...
- Windows7下修改pip源
以下列举三种方式的pip源配置: 1. 设置环境变量PIP_CONFIG_FILE指向pip.ini源配置文件,pip.ini文件内容如下: [global] index-url = http://m ...
- C#中一些字符串操作的经常使用使用方法
概述 本篇主要解说,字符串string的基本操作知识 倒序输出 string str = Console.ReadLine(); for (int i = str.Length - 1; i > ...
- 44.Node.js Express 框架--web框架
转自:http://www.runoob.com/nodejs/nodejs-express-framework.html Express 简介 Express 是一个简洁而灵活的 node.js W ...
- 关于exports 和 module.exports
本文来源为node.js社区附上链接 http://cnodejs.org/topic/5231a630101e574521e45ef8 require 用来加载代码,而 exports 和 modu ...
- IOS 一句代码搞定启动引导页
前言引导页,一个酷炫的页面,自从微博用了之后一下就火起来了,对于现在来说一个app如果没有引导页似乎总显那么不接地气,那么为了让我们的app也“高大上”一次,我写了一个demo来实现启动引导页的实现, ...
- bash命令集---文件的操作
git bash命令集: clear:清除窗口中的内容 ls touch cat more head tail mv cp rm diff chmod gzip gunzip gzcat lpr lp ...
- js--基于面向对象的组件开发及案例
组件的开发:多组对象之间想兄弟关系一样,代码复用的形式. 问题:1).参数不写会报错:利用对象复制————配置参数和默认惨啊书的覆盖关系(逻辑或也可以)2).参数特别多时会出现顺序问题:json解决 ...
- Linux网卡驱动框架及制作虚拟网卡
1.概述 网卡驱动与硬件相关,主要负责收发网络的数据包,将上层协议传递下来的数据包以特定的媒介访问控制方式进行发送,并将接收到的数据包传递给上层协议. 网卡设备与字符设备,块设备不同,网络设备驱动程序 ...