标号 搜 完了……

//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,t,xx[]={1,-1,0,0,0},yy[]={0,0,1,-1,0},map[666][666],vis[666][555];
struct Node{int x,y,t;}node[100050],jy;
queue<Node>q;
bool check(int x,int y){
return x>=0&&y>=0&&x<=600&&y<=600;
}
int main(){
memset(map,-1,sizeof(map));
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&node[i].x,&node[i].y,&node[i].t);
for(int j=0;j<=4;j++){
int x=node[i].x,y=node[i].y;
if(check(x+xx[j],y+yy[j])&&(map[x+xx[j]][y+yy[j]]==-1||(node[i].t<map[x+xx[j]][y+yy[j]]&&~map[x+xx[j]][y+yy[j]]))){
map[x+xx[j]][y+yy[j]]=node[i].t;
}
}
}
q.push(jy);
while(!q.empty()){
Node top=q.front();q.pop();
for(int i=0;i<=3;i++){
int x=top.x,y=top.y;
if(map[x][y]==-1&&(x||y)){printf("%d\n",top.t);return 0;}
if(!vis[x+xx[i]][y+yy[i]]&&check(x+xx[i],y+yy[i])&&(top.t+1<map[x+xx[i]][y+yy[i]]||map[x+xx[i]][y+yy[i]]==-1)){
vis[x+xx[i]][y+yy[i]]=1;
jy.x=x+xx[i];jy.y=y+yy[i];jy.t=top.t+1;
q.push(jy);
}
}
}
puts("-1");
}

POJ 3669 简单BFS的更多相关文章

  1. poj 3414(简单bfs)

    题目链接:http://poj.org/problem?id=3414 思路:bfs简单应用,增对瓶A或者瓶B进行分析就可以了,一共6种状态. #include<iostream> #in ...

  2. POJ 1101 简单BFS+题意

    The Game 题意: Description One morning, you wake up and think: "I am such a good programmer. Why ...

  3. poj 3278 简单BFS

    题意:给定农夫和奶牛的初始位置,农夫可以当前位置+1.-1.*2三种移动方式,问最少需要多少分钟抓住奶牛 AC代码: #include<cstdio> #include<cstrin ...

  4. Meteor Shower POJ - 3669 (bfs+优先队列)

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26455   Accepted: 6856 De ...

  5. POJ3185(简单BFS,主要做测试使用)

    没事做水了一道POJ的简单BFS的题目 这道题的数据范围是20,所以状态总数就是(1<<20) 第一次提交使用STL的queue,并且是在队首判断是否达到终点,达到终点就退出,超时:(其实 ...

  6. 【POJ 3669 Meteor Shower】简单BFS

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

  7. POJ 3669 Meteor Shower【BFS】

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

  8. LightOJ 1012 简单bfs,水

    1.LightOJ 1012  Guilty Prince  简单bfs 2.总结:水 题意:迷宫,求有多少位置可去 #include<iostream> #include<cstr ...

  9. POJ 3669 Meteor Shower(流星雨)

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

随机推荐

  1. [ReactVR] Add Lighting Using Light Components in React VR

    In order to illuminate a scene containing 3D objects a lighting setup is required. In this lesson we ...

  2. iOS开发中的NSDateFormatter日期格式解析总结

    在工作中,常常遇到将时间解析出来转换成自己相应要求的时间格式,之前也有收集相应的转换格式,如今将自己收集的一部分了做个分享,应该比較完好了,欢迎大家继续补充 年 y 将年份 (0-9) 显示为不带前导 ...

  3. html屏蔽鼠标右键

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. mpi之MPI_Sendrecv的用法

    mpi变成常用命令 编译c程序 gcc  例: gcc -Wall -o my_sa my_sa.c  若要编译c++,需要连接, 加参数 gcc -Wall -o my_sa my_sa.cpp - ...

  5. Spark 运行机制及原理分析

  6. HDU 2122 Ice_cream’s world III【最小生成树】

    解题思路:基础的最小生成树反思:不明白为什么i从1开始取,就一直WA,难道是因为村庄的编号是从0开始的吗 Ice_cream’s world III Time Limit: 3000/1000 MS ...

  7. FastDFS图片服务器搭建

    *FastDFS图片服务器搭建准备:1.需要libfastcommon安装包 选择最新稳定版(libfastcommon-1.0.36.tar.gz)2.需要FastDFS安装包 选择最新稳定版(fa ...

  8. Lorenzini:Laplacian与图上的黎曼-罗赫定理

    前两天去听了一下搞代数几何的Dino Lorenzini在交大的两场讲座(“On Laplacian Of Graphs and Generalization”,“Riemann-Roch Theor ...

  9. 05004_Linux的其他命令和权限命令

    1.其他命令 (1)显示当前所在位置 命令:pwd (2)搜索命令 a.命令:grep 要搜索的字符串 要搜索的文件 示例:搜索/etc/sudu.conf文件中包含字符串to的行 b.搜索/etc/ ...

  10. 【hackerrank week of code 26】Hard Homework

    [题目链接]:https://www.hackerrank.com/contests/w26/challenges/hard-homework/problem [题意] 给你一个式子:sin(x)+s ...