• 题意:你刚开始位于坐标轴的\((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. select 里面带的值居然是估算的?

    mysql> set profiling=1;Query OK, 0 rows affected, 1 warning (0.07 sec) mysql> select count(1) ...

  2. 【Linux】CentOS8 初体验

    一.部署CentOS8虚拟机 1.下载Centos8镜像 下载地址: https://www.centos.org/download/ 可以选择国内的下载源,比较快,这里推荐清华的和阿里的 2.下载完 ...

  3. 【Linux】java.io.IOException: error=24, Too many open files解决

    linux系统中执行java程序的时候,如果打开文件超过了限制,就会报错: java.io.IOException: error=24, Too many open files 解决办法: 首先查看j ...

  4. 【Oracle】密码文件相关

    Oracle数据库的orapwd命令,主要用来建立密码(口令)文件. 一.查看帮助信息 [oracle@oracle11g dbs]$ orapwd Usage: orapwd file=<fn ...

  5. 【RAC】11gRAC 搭建(VMware+裸设备)

    安装环境与网络规划 安装环境 主机操作系统:windows 7虚拟机VMware12:两台Oracle Linux R6 U5 x86_64 Oracle Database software: Ora ...

  6. ctfhub技能树—文件上传—无验证

    打开靶机 查看页面信息 编写一句话木马 <?php echo "123"; @eval(@$_POST['a']); ?> 上传木马 上传成功,并拿到相对路径地址 查看 ...

  7. 记忆中的像素块褪色了吗?用开源的体素编辑器重新做个 3D 的吧!

    本文适合对图形表现有兴趣的美术或者开发人员 本文作者:HelloGitHub-Joey 早期的的显示设备像素颗粒较大,使得显示内容的颗粒感严重,像是由一堆方块组成的.比较好的例子就是 GBA 上的游戏 ...

  8. 最佳的思维导图生成工具——markmap 使用教程

    前言 相信很多程序员朋友都有在用 Markdown 吧,我是大三找实习工作的时候接触到的,简历就是用 Markdown 写的. Markdown 的好处是专注码字的同时还能兼顾排版,不用像 word ...

  9. FTP使用Socket SSL流程认证(一)

    关于Ftp使用SSL流程认证 本文章使用的是C#,ftp服务器为FileZilla 注:如果不是使用的Socket可以使用FtpWebRequst类,说实话,该类比较简单,但现在说的是SOCKET,网 ...

  10. Qt QMenuBar和QMenu以及QAction巧妙的使用方法

    这里简单介绍QMenuBar和QMenu以及QAction是什么,其详细功能本文不做介绍,如果还不了解的朋友可以查阅Qt的帮助手册或浏览其它相关博客.如下图,软件中蓝色条框是QMenuBar用来承载Q ...