题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去。如果能输出最短时间。

析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了。

主要思路是这样的,先标记所有的炸弹的位置,和时间,在数组中标记就好,只要赋值给它的爆炸时间就好,注意如果有多个,要赋值最小的那个,

然后用BFS走就行了。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 300 + 15;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int m, n;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int s[maxn][maxn];
int vis[maxn][maxn];
struct node{
int x, y, d;
node(int xx, int yy, int dd) : x(xx), y(yy), d(dd) { }
}; int bfs(){
queue<node> q;
q.push(node(0, 0, 0));
vis[0][0] = 1;
if(!s[0][0]) return -1;
while(!q.empty()){
node u = q.front(); q.pop();
for(int i = 0; i < 4; ++i){
int x = u.x + dr[i];
int y = u.y + dc[i];
if(x < 0 || y < 0 || x > 305 || y > 305 || vis[x][y] || s[x][y] <= u.d+1) continue;
vis[x][y] = 1;
if(s[x][y] == INF) return u.d+1;
q.push(node(x, y, u.d+1));
}
}
return -1;
} int main(){
while(scanf("%d", &n) == 1){
int x, y, t;
for(int i = 0; i < 305; ++i)
for(int j = 0; j < 305; ++j)
s[i][j] = INF;
for(int i = 0; i < n; ++i){
scanf("%d %d %d", &x, &y, &t);
if(x > 0) s[x-1][y] = min(t, s[x-1][y]);
if(y > 0) s[x][y-1] = min(t, s[x][y-1]);
s[x+1][y] = min(t, s[x+1][y]);
s[x][y+1] = min(t, s[x][y+1]);
s[x][y] = min(t, s[x][y]);
}
memset(vis, 0, sizeof(vis));
printf("%d\n", bfs());
}
return 0;
}

POJ 3369 Meteor Shower (BFS,水题)的更多相关文章

  1. POJ 3669 Meteor Shower BFS 水~

    http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...

  2. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  3. POJ 3669 Meteor Shower BFS求最小时间

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31358   Accepted: 8064 De ...

  4. POJ 3126 Prime Path bfs, 水题 难度:0

    题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...

  5. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  6. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  7. poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  8. POJ 3669 Meteor Shower (BFS+预处理)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  9. 题解报告:poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

随机推荐

  1. objcopy

    objcopy objcopy [options] infile [outfile] Copy the contents of the input object file to another fil ...

  2. I.MX6 Ubuntu core porting

    /*********************************************************************** * I.MX6 Ubuntu core porting ...

  3. LeetCode: Sorted Color

    Title: Given an array with n objects colored red, white or blue, sort them so that objects of the sa ...

  4. 【MySQL for Mac】在Mac终端导入&导出.sql文件

    导入 打开终端输入:(前提是已经配置过MySQL环境变量) mysql -u root -p create database name; use name; source 『将.sql文件直接拖拽至终 ...

  5. 【WEB小工具】jQuery函数

    jQuery-API帮助文档:Click here jQuery简介 jQuery是JavaScript框架,jQuery也是JavaScript代码.使用jQuery要比直接使用JavaScript ...

  6. Oracle 课程八之性能优化之10046事件

    Oracle 的事件很多. 具体参考blog: Oracle 跟踪事件 set event 转摘:http://blog.csdn.net/tianlesoftware/archive/2009/12 ...

  7. 国外主流PHP框架比较

    最近简单的使用了目前在国内用的比较多的几个主流国外PHP框架(不包括国内框架),大致对这些框架有个直观上的感受,简单分享一下,对于哪些做框架选型的时候,权当一个参考. 主要参考的框架包括:CodeIg ...

  8. git中reset与revert的使用

    http://alpha-blog.wanglianghome.org/2010/07/30/git-partial-rollback/ reset(版本撤回) 格式 git reset [-q] [ ...

  9. SQL之50个常用的SQL语句

    50个常用的sql语句 Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,T ...

  10. 抽屉显示控件SlidingDrawer入门

    SlidingDrawer是一个抽屉控件,代码具体路径为:android.widget.SlidingDrawer,该控件从API  Level3引入,在API 17及之后的版本将不再被支持.具体效果 ...