• 题意:你刚开始位于坐标轴的\((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. 编译安装PHP - 7.3.16

    编译安装PHP - 7.3.16 1 ) 安装依赖包: yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg ...

  2. Java JDBC的 url 配置信息和Mybatis核心配置文件(MySQL 的配置信息)

    JDBC 连接数据库的 url driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/smbms?uesSSL=true&u ...

  3. 【ORACLE】awr报告问题分析

    本文转自:http://www.linuxidc.com/Linux/2015-10/123959.htm 感谢分享 1.问题说明 运维人员都有"节日休假恐怖症",越到节日.休假和 ...

  4. 关于BAPI_GOODSMVT_CREATE中货物移动相关事务代码说明

    BAPI_GOODSMVT_CREATE参数 goodsmvt_code中的GM_CODE是为 BAPI 货物移动分配事务代码 其取值为下面对应的事务代码: 01 MB0102 MB3103 MB1A ...

  5. Java基础复习4

    选择排序(擂台排序): public class demo1 {     public static void main(String[] args) {          // TODO Auto- ...

  6. Python执行程序实可视化_heartrate

    最近发现了一个Python程序执行的简单实时可视化神器,名字叫 heartrate,安装完运行可以看到下面这样的炫酷过程. 虽然很炫酷,但有点看不懂. 来解释下,左边的动态数字代表每行被触发的次数.变 ...

  7. JavaScript中的Promise【期约】[未完成]

    JavaScript中的Promise[期约] 期约主要有两大用途 首先是抽象地表示一个异步操作.期约的状态代表期约是否完成. 比如,假设期约要向服务器发送一个 HTTP 请求.请求返回 200~29 ...

  8. C++旋转数组(三种解法详解)

    题目描述 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 附加要求 尽可能想出更多的解决方案,至少有三种不同的方法可以解决这个问题. 你可以使用空间复杂度为 O(1) 的 原地 ...

  9. Bitter.Core系列三:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之 示例模型创建

    在具体数据库操作之前,我们先准备好四张表以及相对应数据库操作模型: 学生表,年级表,班级表,学分表.示例数据库表,如下代码(MSSQL 为例) --学生表 CREATE TABLE t_student ...

  10. Optimistic concurrency control 死锁 悲观锁 乐观锁 自旋锁

    Optimistic concurrency control https://en.wikipedia.org/wiki/Optimistic_concurrency_control Optimist ...