本题用时:01:44:20.

算法:BFS

期间固然去逛了逛淘宝买了两个东西,但毕竟还是太久了。我因为忘记判断是否出界而浪费了好多时间,后来才半天想起来,这便是用了这么长时间的原因。

之后提交代码只有六十多分,剩下的点TLE了,我马上反应过来是没判重,赶紧加了个判重。在这里,我没加判重是失误,但立刻能想起来判重而不是继续浪费好多时间才想起来也是一种进步了,希望下次能直接加上判重,不要吝啬判重需要的一点小空间。

Code

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std; struct meteor
{
int x,y,t;
};
meteor V[50005];
struct pt
{
int x,y,t;
pt(int X,int Y,int T){x=X;y=Y;t=T;}
};//pt和meteor是相同的类,但是代表不同的含义,所以分别定义能让代码更加清晰.当然了,类继承能让代码更简洁,但这里就不用了
queue<pt> q;
int M,p,m[305][305],n[305][305],gone[305][305],b[1005];
const int movex[5]={0,0,0,1,-1},
movey[5]={0,1,-1,0,0}; bool cmp(meteor A,meteor B){return A.t<B.t;} int main()
{
cin>>M;
for(int i=0;i<M;i++)
{
cin>>V[i].x>>V[i].y>>V[i].t;
for(int j=0;j<=4;j++)
if(V[i].x+movex[j]>=0&&V[i].x+movex[j]<M
&&V[i].y+movey[j]>=0&&V[i].y+movey[j]<M)
m[V[i].x+movex[j]][V[i].y+movey[j]]=1;
}
sort(V,V+M,cmp);
q.push(pt(0,0,0));
while(!q.empty())
{
pt tpt=q.front();q.pop();
if(gone[tpt.x][tpt.y]==1)continue;
gone[tpt.x][tpt.y]=1;
if(m[tpt.x][tpt.y]==0)
{
cout<<tpt.t<<endl;
return 0;
}
if(b[tpt.t]==0)
for(b[tpt.t]=1;V[p].t<=tpt.t+1;p++)
for(int j=0;j<=4;j++)
if(V[p].x+movex[j]>=0&&V[p].x+movex[j]<M
&&V[p].y+movey[j]>=0&&V[p].y+movey[j]<M)
n[V[p].x+movex[j]][V[p].y+movey[j]]=1;
for(int j=1;j<=4;j++)
if(tpt.x+movex[j]>=0&&tpt.x+movex[j]<M&&tpt.y+movey[j]>=0&&tpt.y+movey[j]<M
&&n[tpt.x+movex[j]][tpt.y+movey[j]]==0&&gone[tpt.x+movex[j]][tpt.y+movey[j]]==0)
q.push(pt(tpt.x+movex[j],tpt.y+movey[j],tpt.t+1));
}
cout<<-1<<endl;
return 0;
}

P2895的更多相关文章

  1. bzoj1611 / P2895 [USACO08FEB]流星雨Meteor Shower

    P2895 [USACO08FEB]流星雨Meteor Shower 给每个点标记一下能够走的最迟时间,蓝后bfs处理一下 #include<iostream> #include<c ...

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

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

  3. P2895 [USACO08FEB]流星雨Meteor Shower

    传送门 预处理出每个位置最早被摧毁的时间,在此之前都可以走 直接dfs加个记忆化和最优性剪枝就好了 一定要注意流星的边界,如果波及到负数坐标的位置不要去考虑会RE 一定要考虑流星砸到边界的情况 如 ( ...

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

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

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

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

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

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

  7. 洛谷 P2895 [USACO08FEB]Meteor Shower S (BFS)

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

随机推荐

  1. java制作游戏,如何使用libgdx,入门级别教学

    第一步,进入libgdx的官网.点击get started 进入这个页面,点击setup a project 进入这个页面直接点击,Generate a project. 点击下载,下载创建工具 它会 ...

  2. Chrome扩展的核心:manifest 文件(中)

    大家好,我是 dom 哥.我正在写关于 Chrome 扩展开发的系列文章,感兴趣的可以 点个小星星 . 在上一篇中已经完成了 Chrome 扩展的雏形,本篇接着介绍 manifest 中的可选字段,完 ...

  3. MybatisPlus查询时过滤不需要的字段~

    解释一下:乍一看标题可能有点懵~,其实就是想查询的时候过滤掉某些字段 例如: select name,email,password from user; --改为-> select name,e ...

  4. Codeforces-470 div2 C题

    C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. 开源.NetCore通用工具库Xmtool使用连载 - 图像处理篇

    [Github源码] <上一篇> 介绍了Xmtool工具库中的扩展动态对象,今天我们继续为大家介绍其中的图像处理类库. 在我们的软件系统中,经常需要对图片进行各种各样的处理:例如最常见的头 ...

  6. 【C#】【IO】【Threading】【实例】工作报表前的本地数据聚合操作

    <工作记录--Report> 报表前的数据获取操作是高重复性的,今天差不多完成了脚本,下述是代码: 1 // See https://aka.ms/new-console-template ...

  7. ElasticSearch之Refresh API

    使用本方法,显式的执行refresh操作. 默认情况下,ElasticSearch启动后台任务,周期性执行refresh操作,周期使用参数index.refresh_interval控制. 本方法触发 ...

  8. 【scikit-learn基础】--『监督学习』之 K-近邻分类

    KNN(K-近邻),全称K-Nearest Neighbors,是一种常用的分类算法.KNN算法的历史可以追溯到1957年,当时Cover和Hart提出了"最近邻分类"的概念.但是 ...

  9. Windows 设置 VMware workstation 虚拟机开机启动

    参考 https://www.cnblogs.com/qmfsun/p/6284236.html http://www.cnblogs.com/eliteboy/p/7838091.html 司徒晓宇 ...

  10. Reactor 简介

    官方的介绍如下: Reactor is a fully non-blocking reactive programming foundation for the JVM, with efficient ...