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& ...
随机推荐
- PHP 使用Apache 中的ab 測试站点的压力性能
打开Apacheserver的安装路径(我用的是 WampServer),在bin文件夹中有一个ab.exe的可运行程序,它就是要介绍的压力測试工具. watermark/2/text/aHR0cDo ...
- 《SAS编程与数据挖掘商业案例》学习笔记之十六
<SAS编程与数据挖掘商业案例>学习笔记,本次重点:sas宏变量 内容包含:宏变量.宏函数.宏參数.通配函数.字符函数.计算函数.引用函数.宏语句.宏应用 1.宏触发器: %name-to ...
- Android学习笔记之图像颜色处理(ColorMatrix)
对图像进行颜色方面的处理,通过使用颜色矩阵(ColorMatrix)来实现.从而可以达到很多特效如黑白老照片.泛黄旧照片等等. 1.颜色矩阵(ColorMatrix) 这里有详细的介绍:http:// ...
- 游标 scroll
scroll表示可随意移动游标指针(否则只能向前)
- chkconfig---检查设置系统服务
chkconfig命令 chkconfig命令检查.设置系统的各种服务.这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务 ...
- PLSQL乱码&TNS-12557: protocol adapter not loadable解决
PLSQL乱码&TNS-12557: protocol adapter not loadable解决 PLSQL乱码&TNS-12557: protocol adapter not l ...
- 洛谷 P2837 晚餐队列安排
P2837 晚餐队列安排 题目背景 Usaco Feb08 Bronze 题目描述 为了避免餐厅过分拥挤,FJ要求奶牛们分2批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想,所有第2批就餐 ...
- Cocos2d-x 之大牛看法
(未完毕) cocos2d-x并非一个适合网游client(mmo)的游戏引擎.越是大型游戏,这个小引擎就越无法驾驭(尽管它很受欢迎). 之前我在原来的公司使用的是自主研发的C3引擎,已经对外开放(尚 ...
- java——简单理解线程
一·[概念] 一般来说,我们把正在计算机中运行的程序叫做"进程"(process),而不将其称为"程序"(program). 所谓"线程& ...
- UML绘图总结
九种图总算画完了,着实让自己纠结了老一阵子啊. 只是,幸运的是完毕了,尽管还有些不足之处,可是终于战胜它了.以下说一下自己的绘图过程 一.用例图 UML的第一幅图应该说是用例图了,这是我们绘图的前提 ...