这题的话,卡了有两个小时左右,首先更新地图的时候越界了,我们进行更新的时候,要判断一下是不是小于零了,越界就会Runtime Error。

然后bfs 的时候,我没有允许它搜出300以外的范围,然后就在300以内搜,然后就错了,实际上题目的意思是流星雨的轰炸范围是0~300,然后我就把世界理解成了300,哼,英文很烂,难受。

所以地图开的大一点,然后直接搜就可以了,这题的思路还是好想的。

#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int INF = 0x3f3f3f3f;
int map[305][305];
int vis[305][305];
int d[5][2] = {{0, 0}, {1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int m; struct Step {
int x, y, t;
Step(int a,int b,int c):x(a),y(b),t(c){}
}; int bfs()
{
if (!map[0][0])
return INF;
vis[0][0] = 1;
queue<Step> q;
q.push(Step(0, 0, 0));
while (!q.empty()) {
Step now = q.front();
if (map[now.x][now.y]==INF)
return now.t;
for (int i = 1; i < 5;i++) {
int dx = now.x + d[i][0];
int dy = now.y + d[i][1];
if (dx>=0&&dy>=0&&map[dx][dy]>now.t+1&&!vis[dx][dy]) {
vis[dx][dy]=1;
q.push(Step(dx, dy, now.t + 1));
}
}
q.pop();
}
return INF;
} int main()
{
int x, y, t;
while (scanf("%d",&m)!=EOF) {
memset(map, INF, sizeof(map));
memset(vis, 0, sizeof(vis));
while (m--) {
scanf("%d%d%d", &x, &y, &t);
for (int i = 0; i < 5;i++) {
int dx = x + d[i][0];
int dy = y + d[i][1];
if (dx>=0&&dy>=0&&t<map[dx][dy]) {
map[dx][dy]=t;
}
}
}
int min=bfs();
printf("%d\n", min == INF ? -1 : min);
}
return 0;
}

POJ-3669-流星雨的更多相关文章

  1. POJ 3669 Meteor Shower(流星雨)

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

  2. POJ 3669 Meteor Shower【BFS】

    POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...

  3. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  4. 广搜最短路(最短时间到达目的地),POJ(3669)

    题目链接:http://poj.org/problem?id=3669 解题报告: 1.流星坠落的点,四周和自己本身都被毁灭,不断更新每个点被毁灭的时候的最短时间. 2.搜索终点是,到达某个点,这个不 ...

  5. POJ 3669 Meteor Shower BFS 水~

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

  6. BFS:Meteor Shower(POJ 3669)

         奔跑吧,傻牛 题目大意:这只Bessie的牛又要来闹事了,这次她的任务就是来躲流星雨,流星雨就是在一定时间会从天上砸到Bessie的所在的正方形区域内(Bessie在0,0的位置),然后砸下 ...

  7. poj 3669 Meteor Shower

                                                                                                      Me ...

  8. POJ 3669 广度优先搜索

    题意:巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内).已知每移动一格需要1个时间单 ...

  9. poj 3669 Meteor Shower(bfs)

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

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

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

随机推荐

  1. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:2. IoT 客户端

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  2. perl 打开二进制文件,并拷贝内容

    实现脚本 use strict ; my $fileName = "/Users/chenfool/Desktop/sequoiadb-大数据平台构建.pdf" ; my $out ...

  3. B - Halloween Costumes

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...

  4. 转 PHP界面显示中文乱码

    D:\wamp64\trainning\testD:\wamp64\www\practice php 页面前端显示乱码 在写一个表单提交的项目中,遇到了PHP界面输出无法显示中文界面. 后来查阅相关资 ...

  5. 089 Gray Code 格雷编码

    格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异.给定一个代表编码总位数的非负整数 n,打印格雷码序列.格雷码序列必须以0开头.例如, 给定 n = 2, 返回 [0,1,3 ...

  6. 安卓新的联网方式 Volley的使用(2)

    如果使用volley 获取 网络图片 最好还是用 Volley 提供的NetworkImageView类,  可以很轻松的 完成工作, 而且他可以设置缓存, lru 和 sd卡的缓存.一些都封装好了. ...

  7. disasters

    1.list all the natural disasters to the best of your knowledge. 2.What are the possible causes for s ...

  8. Linux查看某个端口是否启动

    查看命令 netstat -an | 执行结果: [root@test ~]# netstat -an | tcp 0.0.0.0:* LISTEN 有tcp 这一行返回说明已开放

  9. 将Form以强类型Model提交,后台获取不到的问题

    F.TextBoxFor(m => m.Name) 不能自定ID属性

  10. 一个简单的注册页面,基于JS

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...