Fire!

智能网联汽车电子电气架构(下) 从资产的表现形式, 可以分为数据、 软件、 硬件、 服务等, 而从需要保护的业务过程和活动、 所关注信息的角度, 资产类型可包括基于 ECU 的控制功能、 与特定车辆相关的信息、 车辆状态信息、 用户信息、 配置信息、 特定的软件、 内容等。面向新一代 EEA 的安全需求, 基于芯片提供的 OTP, 或SHE\HSM 的安全存储能力, 实现系统关键数据(身份、 密钥等关键信息) 的安全存储, 保证系统的关键数据不被盗取、 破坏、 改写。结合攻击者的动机与识别出的系统用例, 分析对汽车电子系统可能的攻击。 阅读详情

11624 Fire!
Joe works in a maze. Unfortunately, portions of the maze have caught
on fire, and the owner of the maze neglected to create a fire escape plan.
Help Joe escape the maze.
Given Joe’s location in the maze and which squares of the maze are
on fire, you must determine whether Joe can exit the maze before the
fire reaches him, and how fast he can do it.
Joe and the fire each move one square per minute, vertically or
horizontally (not diagonally). The fire spreads all four directions from
each square that is on fire. Joe may exit the maze from any square
that borders the edge of the maze. Neither Joe nor the fire may enter
a square that is occupied by a wall.
Input
The first line of input contains a single integer, the number of test cases
to follow. The first line of each test case contains the two integers R
and C, separated by spaces, with 1 ≤ R, C ≤ 1000. The following R lines of the test case each contain
one row of the maze. Each of these lines contains exactly C characters, and each of these characters is
one of:
• #, a wall
• ., a passable square
• J, Joe’s initial position in the maze, which is a passable square
• F, a square that is on fire
There will be exactly one J in each test case.
Output
For each test case, output a single line containing ‘IMPOSSIBLE’ if Joe cannot exit the maze before the
fire reaches him, or an integer giving the earliest time Joe can safely exit the maze, in minutes.
Sample Input
2
4 4

#

JF

..

..

3 3

#

J.

.F

Sample Output
3
IMPOSSIBLE
f代表火源,向周围蔓延,然后问这个人能不能跑出去。这个题一下子就想起来上次福州校赛的那个搜索题,一模一样。现在看之后,每个坐标设置两个属性,一个是火到的时间,另一个是人到的时间,如果人到的时间小于火,那就能到达这个地方,继续搜,思路很明了,哦也!
然而,首先,火源不止一个……wa×1;
其次,输入输出最好用scanf,换行用\n;wa×1;
最后,火源要一口气全入队,我傻逼的一个一个入队搜索了……wa×1;
读题,操作技巧,处理方法都不过关。

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
int r, c, leap[1005][1005];
int dir[4][2] = { 1, 0, -1, 0, 0, 1, 0, -1 };
int min(int a, int b)
{
    return a < b ? a : b;
}
struct Node{
    int x;
    int y;
    char c;
    int ans1;
    int ans2;
}node[1005][1005];
Node now[1000007];
queue<Node>p;
void bfs(int k)
{
    int x2, y2, i, j, tempx, tempy;
    Node temp;
    for (i = 1; i <= r; i++)
    for (j = 1; j <= c; j++)
        leap[i][j] = 0;
    for (i = 1; i <= k; i++)
    {
        temp = now[i];
        leap[temp.x][temp.y] = 1;
        p.push(temp);
    }
    while (p.size())
    {
        temp = p.front();
        for (i = 0; i < 4; i++)
        {
            tempx = temp.x + dir[i][0];
            tempy = temp.y + dir[i][1];
            if (tempx >= 1 && tempx <= r&&tempy >= 1 && tempy <= c)
            {
                if (!leap[tempx][tempy] && node[tempx][tempy].c != '#')
                {
                    leap[tempx][tempy] = 1;
                    node[tempx][tempy].ans1 = min(node[temp.x][temp.y].ans1 + 1, node[tempx][tempy].ans1);
                    p.push(node[tempx][tempy]);
                }
            }
        }
        p.pop();
    }
}
int main()
{
    int t, i, j, xo, yo, x2, y2, tempx, tempy, time, k;
    Node temp;
    cin >> t;
    while(t--)
    {
        cin >> r >> c;
        getchar();
        k = 0;
        for (i = 1; i <= r; i++)
        {
            for (j = 1; j <= c; j++)
            {
                scanf("%c", &node[i][j].c);
                node[i][j].x = i;
                node[i][j].y = j;
                node[i][j].ans1 = node[i][j].ans2 = 1000007;
                leap[i][j] = 0;
                if (node[i][j].c == 'J')
                {
                    xo = i; yo = j;
                    node[xo][yo].ans2 = 0;
                }
                if (node[i][j].c == 'F')
                {
                    k++;
                    x2 = i; y2 = j;
                    node[x2][y2].ans1 = 0;
                    now[k] = node[i][j];
                }
            }
            getchar();
        }
        bfs(k);

        for (i = 1; i <= r;i++)
        for (j = 1; j <= c; j++)
            leap[i][j] = 0;
        leap[xo][yo] = 1;
        p.push(node[xo][yo]);
        while (p.size())
        {
            temp = p.front();
            for (i = 0; i < 4; i++)
            {
                tempx = temp.x + dir[i][0];
                tempy = temp.y + dir[i][1];
                if (tempx >= 1 && tempx <= r&&tempy >= 1 && tempy <= c)
                {
                    if (!leap[tempx][tempy] && node[tempx][tempy].c != '#')
                    {
                        if (temp.ans2 + 1<node[tempx][tempy].ans1)
                        {
                            node[tempx][tempy].ans2 = temp.ans2 + 1;
                            leap[tempx][tempy] = 1;
                            p.push(node[tempx][tempy]);
                        }
                    }
                }
            }
            p.pop();
        }
        //for (i = 1; i <= r; i++)
        //{
        //  for (j = 1; j <= c; j++)
        //      cout << node[i][j].ans1 << " ";
        //  cout << endl;
        //}
        time = 1000007;
        for (i = 1; i <= c; i++)
        {
            if (node[1][i].c != '#'&&node[1][i].ans2>=0)
                time = min(time, node[1][i].ans2);
            if (node[r][i].c != '#'&&node[r][i].ans2 >= 0)
                time = min(time, node[r][i].ans2);
        }
        for (i = 1; i <= r; i++)
        {
            if (node[i][1].c != '#'&&node[i][1].ans2 >= 0)
                time = min(time, node[i][1].ans2);
            if (node[i][c].c != '#'&&node[i][c].ans2 >= 0)
                time = min(time, node[i][c].ans2);
        }
        if (time == 1000007)
            cout << "IMPOSSIBLE" << "\n";
        else
            cout << time + 1 << "\n";
    }
    return 0;
}
学习QT之应用程序打包发布 一、编译QT程序(release编译) 二、将release文件夹中的可执行文件复制到一个空的文件夹中 三、使用windeployqt打包工程 切换到可执行文件路径,执行windeployqt xxx.exe: 然后就会将程序所需要用到的资源以及库文件生成到可执行文件路径下: 此时应用程序就可以点击运行了。 四、使用Enigma Virtual Box封包(将文件夹内的文件集成为单可执... 阅读详情

相关推荐

ANSYS Twin Builder实战:5步搞定数字孪生模型部署(附ROM配置技巧)

本文详细解析了ANSYS Twin Builder在数字孪生模型部署中的实战应用,重点介绍了ROM(降阶模型)配置技巧。通过5个关键步骤,从环境搭建到工业部署,帮助工程师高效实现高精度三维仿真到轻量化数字孪生的转化,提升预测性维护和系统仿真效率。

weixin_27330481的博客 655

Fire! BFS预处理

题目: Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe's location in...

weixin_41988889的博客 281

模拟调制系统实战:从AM到FM的5种调制方式对比与选型指南

本文深度解析AM、DSB、SSB、VSB、FM五种经典模拟调制方式,从实现电路、频谱效率、抗噪性能及工程成本等维度进行实战对比。通过MATLAB/Simulink仿真案例,提供清晰的选型决策框架,帮助工程师在无人机图传、短波通信、广播系统等具体项目中,根据带宽、功耗和抗干扰需求选择最优方案。

study的专栏 930

[kuangbin]专题一 简单搜索 Fire! UVA - 11624【BFS】

【题目描述】 Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s location in...

inv0ker的博客 234

Windows-Anaconda3+TensorFlow安装教程

测试环境:win10-64位和win7-64位 (系统必须是64位,因为TensorFlow目前只支持64位) 一、安装Anaconda3 1.下载Anaconda3 Anaconda官网链接:link 这里我们选择Windows版本,python3.6-version-64位,如下图所示。 2.下载完成之后,点击安装Anaconda3 注意:安装过程中要选择添加环境变量,如图 待安装完成...

DoctorCuiLab的博客 3086

告别同质化!用PyTorch Geometric手把手实现RGCN处理多关系图数据(附实战代码)

本文详细介绍了如何使用PyTorch Geometric实现关系图卷积网络(RGCN)处理多关系图数据,特别适用于社交网络分析、推荐系统等场景。通过实战代码演示了从数据加载、模型构建到训练优化的完整流程,帮助开发者高效处理异构图数据,提升模型性能。

weixin_30781433的博客 259

UVA-11624 Fire!(bfs)

Problem Description: Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Jo...

一只在校程序猿的技术贴 353

OpenEuler22.03 LTS下Zabbix7.0监控系统的容器化部署避坑指南(含Docker-Compose完整配置)

本文详细介绍了在OpenEuler22.03 LTS操作系统上容器化部署Zabbix7.0监控系统的完整流程,包括Docker引擎配置、Docker-Compose编排、网络模式选择及性能调优等关键步骤。针对OpenEuler环境下的特殊问题提供了解决方案,帮助用户高效搭建稳定可靠的监控系统。

python9snake的博客 267

UVA - 11624 Fire!

Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s location in the maze and which squares of the maze are on fire, you

weixin_51996479的博客 332

Unity四部曲(核心)

需要先改成Cube复杂的展开留到unity进阶再说。

ultraman1234566的博客 2797

告别手动标注!PDMS NakiToolkit插件安装与初体验:以Pipeline工具为例

本文详细介绍了PDMS NakiToolkit插件的安装与使用,特别是其Pipeline工具如何通过自动化标注和材料统计功能大幅提升三维工厂设计效率。从环境准备到实战演示,帮助工程师告别繁琐的手动标注工作,实现项目交付周期的大幅缩短。

weixin_30047059的博客 349

UVA11624---Fire(双bfs)

Fire Time limit 1000 ms Joe works in a maze. Unfortunately,portions of the maze ha...

From now on...的Blogs 303

YOLOv12改进策略【Neck】| 使用CARAFE轻量级通用上采样算子

CARAFE内容感知的特征重新组合。

Limiiiing的博客 664

uva 11624 - Fire!(bfs)

题目链接:uva 11624 - Fire! 先从F开始,做一遍BFS,处理出每个位置着火的时间。再从J开始走,每次只能走到着火时间大于当前时间的点。 #include #include #include #include using namespace std; const int maxn = 1005; const int inf = 0x3f3f3f3f;

不慌不忙、不急不躁 568

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

ACM简单搜索Fire!--BFS

ACM简单搜索Fire!–BFS Joe works in a maze. Unfortunately, portions of the maze havecaught on re, and the owner of the maze neglected to create a reescape plan. Help Joe escape the maze.Given Joe’s locat...

weixin_43918046的博客 374

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

J - Fire! UVA - 11624【多源BFS】

J - Fire! 题意: 房间里起火,人和火可以上下左右走,每分钟都走一格(火是四个方向同时一格),都不能越过墙。人只要走到房间边界(非墙)就可以逃生。给定人、火、墙的位置,如果人能逃生,输出所需时间,如果不能,输出IMPOSSIBLE ...

我于万物之中 254

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Uva 11624 - Fire!

Uva 11624 - Fire! Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the p

long-long-ago 469

uva11624 - Fire!

uva11624 - Fire! 火在蔓延,人在走。火会蔓延,不会熄灭,我们可以确定某个点着火的时间(广搜)。对于J来说,要是他走到某点的时间比火蔓延到该点的时间要短,那么他走到该点的时候,火还没蔓延过来,他就可以走到该点,否则,不能进入该点。 数据地图表示: -1 该点是墙或已经走过,不能走 -2 该点是通道还没有走过,火还没蔓延过来,可以走 ...

weixin_30446613的博客 91

UVA - 11624 Fire!(BFS+ 思维)

UVA - 11624 Fire! 题目 给一个迷宫,起始位置,还有着火点,每过一个时间,着火点都会蔓延,问最终能否从迷宫逃出。 分析 如果没有着火的情况,直接BFS模板题,加上着火的话,可以预处理每个点被蔓延的时间,到时候 bfsbfsbfs 能不能走出去的时候,不能走当前已经着火的地方。 预处理着火的地方,要将所有起始找着火点都加入初始队列,相当于多个源点。 代码 #include <c...

Stormjing的博客 313

E - Fire! (双向bfs)

cf每日一题

jikelk的博客 595

UVA 11624 Fire! (BFS)

题目链接:Fire! 解析:先用bfs处理出Fire到每个格子的最短时间。 然后再使用bfs求出最短时间。 注意:判断能否扩展的时候,要满足在格子着火之前才可以扩展。 AC代码: #include #include #include #include using namespace std; const int maxn = 1000 + 5; char

sxk 644

UVa 11624 Fire!(着火了!)

UVa 11624 - Fire!(着火了!) Time limit: 1.000 seconds Description - 题目描述   Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to...

weixin_30555753的博客 108

UVa 11624 Fire!(多源BFS)

题目链接:UVa 11624 Fire! 今晚好不爽! 多源BFS。 先对人BFS一次,再对火BFS一次,可能有好多块火,那么先把所有火都加入队列中。判断一块区域谁先到,找最小的。 一个一个输入会超时,得一行一行输入。 scanf输入字符不会忽略回车和换行。 #include #include #include #include #include using names

fobdddf的专栏 761

UVA 11624 - Fire!(BFS)

UVA 11624 - Fire! 题目链接 题意:一个迷宫,一些格子着火了,火每秒向周围蔓延,现在J在一个位置,问他能走出迷宫的最小距离 思路:BFS2次,第一次预处理每个位置着火时间,第二次根据这个再BFS一次 代码: #include #include #include using namespace std; const int d[4][2] = {

Remilia's 1161

(BFS)UVA11624 Fire!

传送门:UVA11624 Fire!  注意:可能存在多个火源。 #include&lt;cstdio&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;cstring&gt; #include&lt;cmath&gt; #include&lt;queue&gt; using namespace std;...

239

UVA 11624 Fire!(图论BFS)

UVA 11624 Fire!(图论BFS) 题意:问你Joe需要最少多长时间能走出一个大火蔓延到网格迷宫。迷宫中存在火源和障碍格。 分析: 朴素的做法是用BFS来模拟Joe的走法,然后看他下一步走的格子是否没有火。(判断该格子在当前时刻有没有火,只需要看看与该格子同行或同列的最近火源是哪个,然后算出起火时间即可。这样算可能会超时)        现在由于火源也是和Joe同样的朝4个方向走

code 1524
上一篇: Fire Game
下一篇: 迷宫问题
Techay
博客等级 码龄11年 11粉丝 174原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值