标号 搜 完了……

//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. [Angular] Handle HTTP Errors in Angular with HttpErrorResponse interface

    When communicating with some backend API, data travels over the network using the HTTP protocol. As ...

  2. Servlet体验之旅(二)——Session、Cookie

    我们知道Session和Cookie都是用于会话跟踪的,仅仅是实现的方式不大一样,那么他们到底有什么不同呢?以下跟着我脚步来了解一下: Session.Cookie的含义: Session 一种ser ...

  3. URAL 1457. Heating Main

    space=1&num=1457">1457. Heating Main Time limit: 1.0 second Memory limit: 64 MB Backgrou ...

  4. Leetcode_num1_Single Number

    好久没有做题啦.从今天開始刷Leetcode的题.希望坚持的时间能长一点. 先从ac率最高的Single Number開始吧. 题目: Given an array of integers, ever ...

  5. UVa 12716 GCD XOR (简单证明)

    题意: 问 gcd(i,j) = i ^ j  的对数(j <=i <= N ) N的范围为30000000,有10000组例子 思路:GCD(a,b) = a^b = c GCD(a/c ...

  6. c++:数据类型的推断type_traits

    //推断左值右值引用 void main() { int i(10);//i是左值 有内存实体 int &ri(i); int &&rri(i + 5);//右值引用 cout ...

  7. ASP.NET form method "post" and "get"

    https://forums.asp.net/t/1796310.aspx?ASP+NET+form+method+post+and+get+ GET:  1) Data is appended to ...

  8. 线程进阶:多任务处理(17)——Java中的锁(Unsafe基础)

    在网络层,互联网提供所有应用程序都要使用的两种类型的服务,尽管目前理解这些服务的细节并不重要,但在所有TCP/IP概述中,都不能忽略他们: 无连接分组交付服务(Connectionless Packe ...

  9. HttpWebRequest 表单提交

    /// <summary> /// http请求 /// </summary> public static class ZkWebRequestHelp { /// <s ...

  10. [ Docker ] 映射資料夾

    - docker run -v <host path>:<container path> - 例如:docker run -v /home/adrian/data:/data ...