HDU 1026 Ignatius and the Princess I

“傻瓜”学计量——双重差分DID3(多期双重差分原理+解决方案CSDID原理) 阅读详情
题目 http://acm.hdu.edu.cn/showproblem.php?pid=1026

BFS+优先队列,需要记录路径。

#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;
const int maxn=100;
const int inf=0x7fffffff;

struct map
{
    int  f, x, y, prex, prey, time;
    char c;
    bool operator <(const struct map &m1) const 
    {
        return m1.time<time;
    }
}mp[maxn+10][maxn+10];

int dx[4]={0, 1, 0, -1};
int dy[4]={-1, 0, 1, 0};
int m, n;
char cc[maxn+10];

int BFS()
{
    priority_queue<map> q;
    mp[0][0].time=0, mp[0][0].f=1;
    q.push(mp[0][0]);
    while (!q.empty())
    {
        struct map cur_m=q.top();
        q.pop();
        if (cur_m.x==n-1&&cur_m.y==m-1) return 1;
        for (int i=0; i<4; i++)
        {
            int newx=dx[i]+cur_m.x;
            int newy=dy[i]+cur_m.y;
            if (newx<0||newx>n-1||newy<0||newy>m-1||mp[newx][newy].f==1) continue;
            if (mp[newx][newy].c=='.')
            {
                mp[newx][newy].f=1, mp[newx][newy].time=mp[cur_m.x][cur_m.y].time+1;
                mp[newx][newy].x=newx, mp[newx][newy].y=newy;
                mp[newx][newy].prex=cur_m.x, mp[newx][newy].prey=cur_m.y;    
            }
            else if (isdigit(mp[newx][newy].c))
            {
                mp[newx][newy].f=1, mp[newx][newy].time=mp[cur_m.x][cur_m.y].time+(mp[newx][newy].c-'0')+1;
                mp[newx][newy].x=newx, mp[newx][newy].y=newy;
                mp[newx][newy].prex=cur_m.x, mp[newx][newy].prey=cur_m.y;
            }
            q.push(mp[newx][newy]);
        }
    }
    return 0;
}

void printTrace(int x, int y)
{
    if (x==0&&y==0) return;
    int prex=mp[x][y].prex, prey=mp[x][y].prey;
    printTrace(prex, prey);
    int len1=mp[prex][prey].time, len2=mp[x][y].time;
    printf("%ds:(%d,%d)->(%d,%d)\n", len1+1, prex, prey, x, y);
    for (int i=len1+2; i<=len2; i++) printf("%ds:FIGHT AT (%d,%d)\n", i, x, y);
}
int main()
{
    //freopen("in.txt", "r", stdin);
    while (scanf("%d %d", &n, &m)==2)
    {
        for (int i=0; i<n; i++)
        {    
            scanf("%s", cc);
            for (int j=0; j<m; j++)
            {
                mp[i][j].c=cc[j];
                if (mp[i][j].c=='X') mp[i][j].f=1;
                else mp[i][j].f=0;
                mp[i][j].time=inf, mp[i][j].x=i, mp[i][j].y=j;
            }
        }
        
        if (BFS())
        {
             printf("It takes %d seconds to reach the target position, let me show you the way.\n", mp[n-1][m-1].time);
             printTrace(n-1, m-1);
        }
        else printf("God please help our poor hero.\n");
        printf("FINISH\n");
    }
    return 0;
}

即梦 AI 全功能零基础详细教程(纯技术版) 即梦 AI 是一款多模态 AI 生成工具,主打文本生成视频、图片生成视频、角色一致性生成、音画同步等核心功能,依托自研 AI 视觉模型,实现从文本 / 图片 / 音频素材输入,到高清视频、图像内容输出的全流程 AI 创作,支持短视频、短剧、创意素材等多场景创作,具备操作门槛低、生成效率高、画面可控性强的技术特点。@为工具内置引用指令,作用是锁定指定素材 / 角色,强制 AI 按照该素材的核心特征生成内容,无额外付费、解锁要求,免费使用。剧本拆分:将短剧拆分为单镜头(15 秒内 / 个) 阅读详情

相关推荐

CCS配置MSPM0G3507(七) 编码器(TIMER-QEI)

1.选择时钟源 BUSCLK2.时钟分频配置为1分频3.分频系数配置为14.若勾选 Start ,则生成程序后会自动开启定时器的计数,否则需手动在程序中开启5.Load Value 设置为65535。

kaneki_lh的博客 1万+

hdu 1026 Ignatius and the Princess I

hdu   1026   Ignatius and the Princess I                 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 题目大意:经典二维迷宫问题,魔王、公主与勇士的故事,这不是魔塔么???!!! 题目分析:又是要求输出路径的BFS,还打小怪兽,不过不怕,poj3984打印过路径,hdu1242也

slicer的技术交流栈 824

Cisco Secure ACS 5.8.0.32 安装 + Crack 教程

在ESXi 6.7 上经历过无数次的安装尝试测试了各种兼容版本都没有安装成功,记最后一次安装成功的过程.

Junior's Blog 3535

HDU1026——Ignatius and the Princess I,HDU1027——Ignatius and the Princess II,HDU1028——Ignatius and the

a矩阵:存储迷宫的信息,其中X表示障碍物,表示空地,数字1-9表示需要战斗的格子。flag矩阵:标记格子是否已被访问过。d数组:定义了四个移动方向。node结构体:包含坐标y和x,以及到达该格子的步数step。pre数组:用于记录每个格子的前一个格子,以便回溯路径。

u014114223的博客 2101

Excel聚光灯效果终极指南:VBA代码实现与条件格式避坑技巧

本文详细解析了Excel聚光灯效果的实现方法,包括VBA代码优化与条件格式的避坑技巧。通过模块化编程和性能优化技术,帮助用户高效处理大型数据表格,实现自定义高亮显示,提升数据分析和报表阅读体验。

v6b7n8m9q0的博客 456

IO Virtualization with Virtio.part 2 [十三]

通过对virtio_device_id 中的 device 和 vendor 的值进行比较,我们找到对应的 virtio 驱动,由于这里我们使用 i2c virtio 为例,所以调用 virtio_i2c_probe 进行 virtio i2c 设备的初始化。在和 virtio mmio 设备交互时我们会读取 VIRTIO_MMIO_DEVICE_ID 和 VIRTIO_MMIO_VENDOR_ID,并将其值写入 virtio_device_id 中,这个就会用作后面和 virtio 设备驱动的匹配参数。

cxjczy1990的博客 1211

hdu 1026 Ignatius and the Princess I

hdu 1026 Ignatius and the Princess I         题目要求的是从(0, 0)到(n-1, m-1)的最小秒数啦, 首先想到的就是广搜啦, 这道题要求输出搜索过的路径哦, 那么就需要一个额外的数组来记录了.         用turn[][]数组来记录每次转过的方向, 一次广搜结束后, 然后再从终点顺着走回来, 就可完成路径的记录啦. #incl

happen_zhang 616

大数据知识面试题-Hadoop(2022版)

序列号 内容 链接 1 大数据知识面试题-通用(2022版) 待续… 2 大数据知识面试题-Hadoop(2022版) 待续… 3 大数据知识面试题-MapReduce和yarn(2022版) 待续… 4 大数据知识面试题-Zookeepr (2022版) 待续… 5 大数据知识面试题-Hive (2022版) 待续… 6 大数据知识面试题-Flume(2022版) 待续… 7 大数据知识面试题-Hbase(2022版) 待续… 8 大数据知识面试题-sqoop(....

拉格朗日的学习笔记 1万+

HDU1026 Ignatius and the Princess I

问题链接:HDU1026 Ignatius and the Princess I。 题意简述:从矩阵的左上角走到右下角所需的最短时间,并且要求输出走的过程。矩阵中"."是可以走的,"X"是墙,n(数字1-9)是怪兽,需要战斗数字所示的时间。对于每个测试实例,先输入n和m,分别表示行数和列数,然后输入矩阵。 问题分析:显然求最短路径问题用BFS,另外由于有怪兽...

weixin_33904756的博客 91

cannot import name ‘BUFSIZE‘ from ‘numpy‘ 解决方案

本文主要介绍了cannot import name ‘BUFSIZE’ from ‘numpy’ 解决方案,希望能对使用numpy的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 22万+

YOLOv8改进有效系列目录 | 包含卷积、主干、检测头、注意力机制、Neck上百种创新机制

Hello,各位读者们好,本专栏自开设两个月以来已经更新改进教程120+余篇其中包含C2f、主干、检测头、注意力机制、Neck多种结构上创新,也有损失函数和一些细节点上的创新,订阅本专栏以后你不仅可以收获跟专栏的阅读权限,同时可以进Qq群,里面包含集成我所有创新的YOLO最新目录,和我本人录制的视频讲解教程,如果你想要在YOLOv8系列收获一篇论文,我相信订阅本专栏后你一定会有所收获~YOLOv8改进有效系列目录。

Snu77的博客 18万+

hdu 1026 Ignatius and the Princess I题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 菜鸟第一发。。。 题目大意:给出一张n*m的图,'.'表示道路,'X'表示不能通过的地方,数字n表示怪物的血量(打死需要花费n秒),每走一步需花费一秒,只能往上下左右四个方向走。要求找出从(0, 0)点到(n-1, m-1)点用时最短的路径,并按照样例把路径输出来。 思路:用bfs寻找

pai_pk的博客 334

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

HDU - 1026 Ignatius and the Princess I

The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrinth. To make the problem ...

vocaloid01的博客 305

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU1026——Ignatius and the Princess I

先看题目。 Problem Description The Princess has been abducted by theBEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now hegets into feng5166's castle. The castle is a large labyr

a054545641的博客 378

hdu 1026 Ignatius and the Princess I

题目链接 Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14047    Accepted Submission(s): 4422 Special Judge

大太阳 818

HDU 1026 Ignatius and the Princess I BFS 优先队列

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18557    Accepted Submission(s): 5976 Special Judge Problem

LZK1997的博客 886

HDU 1026 Ignatius and the Princess I

Ignatius and the Princess I                                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)              

Houheshuai的专栏 507

HDU OJ 1026 Ignatius and the Princess I 【搜索+记录路径】

原题连接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意: 给一个 n * m 的矩阵,X 代表墙 . 代表路,若是数字 ,则该点有 怪,需要 打怪。从求 从(0,0 )点 到  (n-1,m-1)点的用时最小的路,要输出路径。 思路:1:求用时最小路----BFS(广搜)+ 优先队列;             2:在搜到一个点时对应记

nyist_飘谊 2671

HDU 1026 Ignatius and the Princess I (BFS+优先队列)

HDU 1026 Ignatius and the Princess I (BFS+优先队列)Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into fen

退役的铜牌狗 385

HDU1026:Ignatius and the Princess I

点击打开题目链接 Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8688    Accepted Submission(s): 2590 Special J

I just want to AC you~~~ 1127
上一篇: HDU 2199 Can you solve this equation?
下一篇: 关于CPU流水线详解...高主频≠高性能
Mei废话
博客等级 码龄14年 5粉丝 24原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值