POJ - 3669 Meteor Shower


Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a safe location (one that is never destroyed by a meteor) . She is currently grazing at the origin in the coordinate plane and wants to move to a new, safer location while avoiding being destroyed by meteors along her way.

The reports say that M meteors (1 ≤ M ≤ 50,000) will strike, with meteor i will striking point (Xi, Yi) (0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300) at time Ti (0 ≤ Ti ≤ 1,000). Each meteor destroys the point that it strikes and also the four rectilinearly adjacent lattice points.

Bessie leaves the origin at time 0 and can travel in the first quadrant and parallel to the axes at the rate of one distance unit per second to any of the (often 4) adjacent rectilinear points that are not yet destroyed by a meteor. She cannot be located on a point at any time greater than or equal to the time it is destroyed).

Determine the minimum time it takes Bessie to get to a safe place.

Input
* Line 1: A single integer: M
* Lines 2..M+1: Line i+1 contains three space-separated integers: Xi, Yi, and Ti

Output
* Line 1: The minimum time it takes Bessie to get to a safe place or -1 if it is impossible.

Sample Input
4
0 0 2
2 1 2
1 1 2
0 3 5


题意:输入n,其实是流星落下,并且流星落下会破坏和它相邻的四个方向的点,我用爆炸点代替,接下来的n行输入炸弹点的坐标(x,y)和该炸弹爆炸的时间,并且该点爆炸,和它相邻的上下左右四个点也会被炸毁,求离开炸弹区域的最短时间。

注意:当爆炸点为(0,0),并且爆炸时间为0时,输出-1,continue。

用二维数组time[ ][ ]存储(x,y)点炸弹爆炸的最小时间,mp[ ][ ]数组标记(x,y)点是否爆炸,用book[ ][ ] 数组标记该点是否已经走过。每一次输入爆炸点的坐标,都要将和它相邻的四个方向标记为爆炸点,并且更新该点和与它相邻的四个方向的点的爆炸时间,得到每一个爆炸点的最短时间。

用队列求到达安全区域的最短时间,若该点的爆炸时间大于当前的时间,并且该点未被标记过,且未出界,该点入队,时间加1。

若找到安全点,输出当前时间。若队列为空时,还未找到安全点输出-1。


#include<queue>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f

int m,f;
int mp[320][320],time[320][320],book[320][320];
int nx[4][2]= {0,-1,-1,0,0,1,1,0};
struct note
{
    int x,y,s;
};

void play(int x,int y,int z)
{
    for(int i=0; i<4; i++)
    {
        int tx=nx[i][0]+x;
        int ty=nx[i][1]+y;
        if(tx>=0&&ty>=0)
        {
            mp[tx][ty]=-1;
            time[tx][ty]=min(time[tx][ty],z);
        }
    }
}

void bfs()
{
    note now,tmp;
    now.x=0;
    now.y=0;
    now.s=0;
    book[0][0]=1;
    queue<note> Q;
    Q.push(now);
    while(!Q.empty())
    {
        now=Q.front();
        Q.pop();
        if(mp[now.x][now.y]==0)
        {
            f=1;
            printf("%d\n",now.s);
            return ;
        }
        for(int i=0; i<4; i++)
        {
            tmp.x=now.x+nx[i][0];
            tmp.y=now.y+nx[i][1];
            tmp.s=now.s+1;
            if(tmp.x>=0&&tmp.y>=0&&!book[tmp.x][tmp.y])
            {
                if(mp[tmp.x][tmp.y]==-1)
                {
                    if(time[tmp.x][tmp.y]>tmp.s)  //如果该点在目前时刻未被炸毁,入队
                    {
                        book[tmp.x][tmp.y]=1;
                        Q.push(tmp);
                    }
                }
                else
                {
                    book[tmp.x][tmp.y]=1;
                    Q.push(tmp);
                }
            }
        }
    }
}

int main()
{
    int a,b,c;
    while(~scanf("%d",&m))
    {
        memset(mp,0,sizeof(mp));
        memset(time,INF,sizeof(time));
        memset(book,0,sizeof(book));
        for(int i=0; i<m; i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            mp[a][b]=-1;
            time[a][b]=min(time[a][b],c);  //这里一定要更新为最小值
            play(a,b,c);
        }
        if(time[0][0]==0 && mp[0][0]==-1)
        {
            printf("-1\n");
            continue;
        }
        f=0;
        bfs();
        if(!f)
            printf("-1\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值