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& ...
随机推荐
- NOIP 模拟赛
NOIP 模拟赛 思路:求 n , m 的 gcd,然后用 n , m 分别除以 gcd:若 n 或 m 为偶数,则输出 1/2. 特别的,当 n = m = 1 时,应输出 1/1 #include ...
- 深入理解javascript之高级定时器
setTimeout()和setInterval()能够用来创建定时器.其主要的用法这里就不再做介绍了.这里主要介绍一下javascript的代码队列. 在javascript中没有不论什么代码是马上 ...
- HDOJ 5419 Victor and Toys 树状数组
分母是一定的C(m,3) 树状数组求每一个数能够在那些段中出现,若x出如今了s段中,分子加上w[x]*C(s,3) Victor and Toys Time Limit: 2000/1000 MS ( ...
- RTSP传输协议之Methods总结
RTSP/1.0 200 OK Server: DSS/5.5.5 (Build/489.16; Platform/Linux; Release/Darwin; state/beta; ) Cseq: ...
- js --- 事件冒泡 事件捕获
先上结论: 他们是描述事件触发时序问题的术语.事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件.相反的,事件冒泡是自下而上的去触发事件.绑定事件方法的第三个参数,就是控制事 ...
- Js经典实例收集
跨浏览器添加事件 //跨浏览器添加事件 function addEvent(obj,type,fn){ if(obj.addEventListener){ obj.addEventListener(t ...
- ElasticSearch 工作原理
ElasticSearch 工作原理图 文字说明,以后更新
- QQ亿级日活跃业务后台核心技术揭秘
http://ms.csdn.net/geek/75478 引言 作为本次技术开放日后台架构专场的出品人我今天给大家带来<构造高可靠海量用户服务-SNG数亿级日活跃业务后台核心技术揭秘>, ...
- 关于我遇到的“LNK 2019无法解析的外部符号”的链接错误
昨天在调试程序的时候出现了"LNK 2019无法解析的外部符号"的问题(VS2008),依照网上说的方法都没有解决这个问题,最后在项目文件里发现有两个同名的可是不在同一个目录下的c ...
- Zabbix监控Tomcat,Redis
一 Tomcat监控 1.1.1 Tomcat 端配置 JMX 编辑catalina.sh文件,配置如下: CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.m ...