• 题意:你刚开始位于坐标轴的\((0,0)\)点,一共有\(m\)颗流星砸向地面,每颗流星在\(t\)时砸到\((x,y)\)点,其四周上下左右也均有波及,你每秒可以向上下左右移动一个单位,问你是否可以移动到安全的地方(没有被流星波及的点),求最小步数.

  • 题解:这题细节有点多,但也是一个基本的bfs,首先我们要用一个数组来记录流星砸向地面的最早时间,然后还要注意你在跑到某个点的时候可能被砸中,然后搞个结构体直接bfs,当找到某个点没有被存时间的数组记录,直接输出即可.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL; struct misaka{
    int x,y,t;
    }p; int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; int m;
    int x,y,t;
    int jikann[400][400];
    int a[400][400]; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    me(jikann,-1,sizeof(jikann));
    cin>>m;
    for(int i=1;i<=m;++i){
    cin>>x>>y>>t;
    if(t<jikann[x][y] || jikann[x][y]==-1){
    jikann[x][y]=t;
    }
    for(int j=0;j<4;++j){
    int tx=x+dx[j];
    int ty=y+dy[j];
    if(tx>=0&&ty>=0&&(t<jikann[tx][ty]||jikann[tx][ty]==-1)){
    jikann[tx][ty]=t;
    }
    }
    }
    p.x=0,p.y=0,p.t=0;
    a[0][0]=1;
    queue<misaka> q;
    q.push(p);
    while(!q.empty()){
    misaka tmp=q.front();
    q.pop();
    for(int i=0;i<4;++i){
    int tx=tmp.x+dx[i];
    int ty=tmp.y+dy[i];
    if(tx>=0&&ty>=0&&a[tx][ty]==0&&(tmp.t+1<jikann[tx][ty]||jikann[tx][ty]==-1)){
    a[tx][ty]=1;
    p.x=tx,p.y=ty,p.t=tmp.t+1;
    q.push(p);
    if(jikann[tx][ty]==-1){
    cout<<p.t<<endl;
    return 0;
    }
    }
    }
    }
    cout<<-1<<endl;
    return 0;
    }

洛谷 P2895 [USACO08FEB]Meteor Shower S (BFS)的更多相关文章

  1. 洛谷—— P2895 [USACO08FEB]流星雨Meteor Shower

    P2895 [USACO08FEB]流星雨Meteor Shower 题目描述 Bessie hears that an extraordinary meteor shower is coming; ...

  2. 洛谷P2895 [USACO08FEB]流星雨Meteor Shower

    题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...

  3. 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower

    题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will ...

  4. 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower 解题报告

    一起来看流星雨吧(话说我还没看到过流星雨呢) 题目 Problem 小A则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...

  5. poj 3669 Meteor Shower(bfs)

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

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

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

  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)

    -->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...

  9. 和小哥哥一起刷洛谷(4) 图论之广度优先搜索BFS

    关于bfs: 你怎么会连这个都不知道!!!自己好好谷歌一下!!!(其实我也刚学) bfs伪代码: while(队列非空){ 取出队首元素u; 弹出队首元素; u染色为黑色; for(int i=0;i ...

随机推荐

  1. [翻译]Azure 网关迁移至 .NET Core 3.1 性能提升一倍

    原文:[Azure Active Directory's gateway is on .NET Core 3.1!] Azure Active Directory 的网关服务是一个反向代理,它为构成 ...

  2. 用其他主机docker login登录Harbor仓库报错

    做微服务的时候,我准备把编译好的jar包,部署到我的Harbor仓库上,却登录不上去,出现以下报错: [root@k8s-master ~]# docker login 192.168.30.24Us ...

  3. 代码 or 指令,浅析ARM架构下的函数的调用过程

    摘要:linux程序运行的状态以及如何推导调用栈. 1.背景知识 1.ARM64寄存器介绍: 2.STP指令详解(ARMV8手册): 我们先看一下指令格式(64bit),以及指令对于寄存机执行结果的影 ...

  4. javax.servlet.ServletException: No adapter for handler

    问题描述: 我的web.xml如下: <?xml version="1.0" encoding="UTF-8"?> <web-app xmln ...

  5. 从HDFS中下载指定文件,如果本地文件与要下载的文件名称相同,则自动对下载的文件重命名。

    1 import org.apache.hadoop.conf.Configuration; 2 import org.apache.hadoop.fs.*; 3 import org.apache. ...

  6. 关于MongoDB的简单理解(一)--基础篇

    一.什么是MongoDB? MongoDB是一个基于分布式文件存储的文档数据库,旨在简化开发和扩展,为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之 ...

  7. threading.RLock()

    # Copyright 2001-2017 by Vinay Sajip. All Rights Reserved.## Permission to use, copy, modify, and di ...

  8. 4. Tomcat调优

    1,     调内存 JVM 2,     调网络处理框架  普通io/nio,netty https://segmentfault.com/a/1190000008873688 https://ww ...

  9. Webpack4.0各个击破(10)integration篇

    一. Integration 下文摘自webpack中文网: 首先我们要消除一个常见的误解,webpack是一个模块打包工具(module bundler),它不是一个任务执行工具,任务执行器是用来自 ...

  10. Mysql 四种事务隔离级别

    一.前提 时过一年重新拾起博文记录,希望后面都能坚持下来. 接着之前MySql的学习,先记录下这篇. 以下都是基于mysql8 innodb存储引擎进行分析的. 二.事务的ACID特性 A(Atomi ...