zoukankan      html  css  js  c++  java
  • POJ 3669 简单BFS

    标号 搜 完了……

    //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
    ",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");
    }

    这里写图片描述

  • 相关阅读:
    使用反射调用某个类的成员方法
    java反射机制
    SVProgressHUD
    __objc__
    loadView
    v2ex 下拉刷新 SCRootViewController
    stuck with
    v2ex 下拉刷新模块
    转载
    vue-cli脚手架构建了项目如何去除Eslint验证(语法格式验证)
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/6532277.html
Copyright © 2011-2022 走看看