POJ 2312 Battle City(优先队列 + BFS)

手把手教你用Synopsys AHB VIP搭建验证环境:从SINGLE到WRAP16的完整波形分析与避坑指南 本文详细介绍了如何使用Synopsys AHB VIP搭建验证环境,从基础配置到复杂波形调试实战。重点解析了AHB协议中各种Burst类型的地址计算机制,包括INCR和WRAP类型,并提供了实际案例和避坑指南,帮助工程师快速掌握验证技巧。 阅读详情

题目链接:POJ 2312 Battle City

打碎砖头需要两步,这里如果直接加到普通的队列中可以说是违反了BFS的规则,所以需要使用优先队列来选择当前队列中步数最少的那个,画画图就很明白了。

记得要清空队列。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

const int MAX_N = 300 + 10;
const int INF = (1 << 29);

struct Point
{
    int x, y, dis;
    friend bool operator < (Point a, Point b)
    {
        return a.dis > b.dis;
    }
    Point (int x, int y, int dis) : x(x), y(y), dis(dis) {};
    Point () {};
};
priority_queue <Point> Q;
int vis[MAX_N][MAX_N];
char _map[MAX_N][MAX_N];
int fx[4] = {0, 1, 0, -1};
int fy[4] = {1, 0, -1, 0};
int N, M, res;

void BFS()
{
    int dx, dy;
    Point a;
    while(!Q.empty())
    {
        a = Q.top();
        if(_map[a.x][a.y] == 'T')
        {
            res = a.dis;
            return ;
        }
        Q.pop();
        for(int i = 0; i < 4; i++)
        {
            dx = a.x + fx[i], dy = a.y + fy[i];
            if(dx >= 0 && dy >= 0 && dx < N && dy < M && !vis[dx][dy] && _map[dx][dy] != 'S' && _map[dx][dy] != 'R')
            {
                vis[dx][dy] = 1;
                if(_map[dx][dy] == 'B')
                    Q.push(Point(dx, dy, a.dis + 2));
                else
                    Q.push(Point(dx, dy, a.dis + 1));
            }
        }
    }
}

int main()
{
    while(scanf("%d%d", &N, &M), N + M)
    {
        memset(vis, 0, sizeof(vis));
        res = INF;
        for(int i = 0; i < N; i++)
        {
            scanf("%s", _map[i]);
            for(int j = 0; j < M; j++)
            {
                if(_map[i][j] == 'Y')
                {
                    vis[i][j] = 1;
                    Q.push(Point(i, j, 0));
                }
            }
        }
        BFS();
        if(res == INF)
            printf("-1\n");
        else
            printf("%d\n", res);
        while(!Q.empty())
            Q.pop();
    }
    return 0;
}


GNSS差分码偏差(DCB)从原理到实战:如何避免数据处理中的常见错误 本文深入解析GNSS差分码偏差(DCB)的原理及其对高精度定位的关键影响。针对数据处理中因忽略DCB校正导致的常见错误,如单系统PPP高程偏差、多系统融合精度下降及电离层研究失真等,提供了实战解决方案与主流DCB产品获取、集成方法,帮助用户有效规避陷阱,提升数据处理精度。 阅读详情

相关推荐

麒麟OS恢复出厂设置原理与实操:非重装的系统状态回滚

Linux操作系统中的‘恢复出厂设置’并非简单重装或镜像还原,而是一种基于状态快照、包管理与配置模板的可控回滚机制。其核心原理依赖LVM快照技术、RPM包签名验证和预置配置模板,兼顾系统稳定性与用户数据安全。该方案在政务、教育等国产化场景中具有显著技术价值——不格式化硬盘、不丢失/home文档、不重配驱动与授权,大幅降低运维复杂度。典型应用场景包括系统卡顿修复、软件冲突清理、桌面环境异常恢复等。本文深入解析银河麒麟V10的kylin-restore-cli工具链与麒麟管家集成逻辑,聚焦‘恢复出厂设置’这一高

weixin_30879169的博客 774

POJ 2312 Battle City 优先队列+BFS

相信坦克大战大家都玩过吧,本题就是根据这个游戏设计的。坦克要从起点(Y),到目的地(T),坦克不能通过钢墙(S),河(R),可以在空地在行走(E),射击破坏砖墙(B),射击砖墙时不行走且花费一个单位的时间,在空地上行走时也花费一个单位的时间。求坦克从起点到目的地最少花多少时间,不

Hackbuteer1的专栏 5532

Intel RealSense D435 深度相机详解

Intel RealSense D435 深度相机是 Intel 推出的一款基于深度感知技术的相机,广泛应用于机器人、无人机、增强现实(AR)、虚拟现实(VR)、3D扫描、智能监控等领域。D435 是 RealSense 系列中较为高端的深度相机之一,结合了深度传感和 RGB 摄像技术,为用户提供高精度的深度数据和高质量的图像捕捉能力。

crasher123的博客 2947

【POJ】2312-Battle City (bfs,优先队列)

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7805   Accepted: 2613 Description Many of us had played the game "Battle city" in our childhood

wyg1997 1070

Trans论文复现:电池储能调峰和调频:超线性增益的联合优化程序代码!

本程序参考一区SCI期刊《Using Battery Storage for Peak Shaving and Frequency Regulation: Joint Optimization for Superlinear Gains》,程序。与之前将电池储能用于单一应用相比,研究结果表明,如果电池联合提供多种服务,它们可以获得比以前想象的更大的经济效益。欢迎感兴趣的小伙伴关注下方公众号获取完整版代码哦~,小编会继续推送更有质量的学习资料、文章程序代码~限于篇幅,仅列出部分算例的结果!

weixin_48747334的博客 567

SIwave仿真手册——软件基础(一)

最近在学习SIWAVE,在这里将自己的笔记整理一下,做一个专题。希望对大家有帮助,这个会持续更新的。仅限于软件操作学习,不涉及信号完整性的讨论。

luohuo9844的博客 4万+

POJ 2312 Battle City(优先队列+BFS)

题目链接:http://poj.org/problem?id=2312 Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7085   Accepted: 2390 Description Many of us had playe

MummyDing's Blog 2491

Bootloader详解,理解Bootloader看这篇就够了

这里写目录标题一、Bootloader作用(目的)二、完成Boot最终目的的前提条件三、对前提条件的详细说明3.1、对前提条件(1)的说明:3.2、对前提条件(2)的说明:3.3、对前提条件(3)的说明:3.4、对前提条件(4)的说明:3.4、对前提条件(5)的说明:四、loader是干啥的 一、Bootloader作用(目的) Bootloader=Boot + loader Boot的目的: 最终目的:跳到C语言中;为了C语言运行程序会进行一系列的初始化,系统一上电后如何通过一系列的设置让软件程序员

iduuigdg的博客 11万+

poj 2312 Battle City(优先队列+bfs)

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7897   Accepted: 2640 Description Many of us had played the game "Battle city" in our childhood,

Calm微笑 517

微信小程序实现锚点效果 scroll-view的scroll-into-view属性

小程序中实现锚点效果,可以直接使用scroll-view的scroll-into-view属性就可以实现锚点效果,比较方便简单。那么需要用到scroll-view那些参数呢,下面具体讲讲:效果展示: wxml **注意:**viewid值是动态的,通过setData设置即可。js wxss......

FaxMiao的博客 5450

STM32解析航模遥控器的PPM信号

使用STM32对航模遥控器的PPM信号进行解析

qq_44343584的博客 9734

POJ 2312 Battle City(优先队列+bfs)

Problem Description Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this g...

wcxyky的博客 266

第14.8章 高翔博士最新开源框架Lightning-LM源码解读(八):位姿平滑器PoseSmoother深度剖析,从原理到代码实现

本文深度解析了高翔博士开源框架Lightning-LM中的位姿平滑器PoseSmoother模块。该模块通过设置平滑因子,在保证位姿准确性的同时减少突变,使位姿变化更平稳。文章详细讲解了模块功能、数据流程和核心代码实现,包括构造函数、拷贝构造函数以及关键的PushDRPose和PushPose函数。重点分析了位姿平滑算法原理,涉及运动有效性校验、位姿队列维护和平滑因子调节等核心机制。此外还介绍了相关C++语法(如显式构造函数、默认拷贝构造)和优化方向。本解析为SLAM学习者提供了位姿平滑处理的实用实现范例。

行知SLAM 605

【bfs+优先队列】POJ2312-Battle City

【思路】 题目中的“可以沿直线发射打破砖墙”可能会迷惑到很多人,实际上可以等价理解为“通过砖墙的时间为2个单位”,这样题目就迎刃而解了。第一次碰到时可能不能很好把握,第二次基本就可以当作水题了。 【错误点】 1.不能用裸的bfs。广搜的实际思想是将到达时间最短的放在队首,这样首次到达终点即为时间的最小值。通过砖墙的时间为两个单位,通过砖墙后可能不是时间最小值。用优先队列可以解决这一...

dianchunhui2654的博客 153

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

bfs解决poj 2312 battle city(优先队列)

Battle City 题目链接 题目描述 简单描述一下,细节点击题目链接进行查看。 给定m,n,然后给定m*n的矩阵,矩阵元素由 ‘Y’ (you), ‘T’ (target), ‘S’ (steel wall), ‘B’ (brick wall), ‘R’ (river) and ‘E’ (empty space)中的几个元素组成,并且’Y’和’T’只出现一次,现要求从Y尽快走到T。 其中B表示的位置必须要射击一次,再走一步才算到达,E表示的位置可走一步直接到达,S和R表示的位置不可通过。 解题思路 要

weixin_43966538的博客 393

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

POJ2312 Battle City(BFS+优先队列)

题目链接 题意: 输入M×N大小的地图,其中’Y’表示起点,'T’表示终点,'S’与’R’表示不可以通过的障碍,'E’表示可以通过,'B’表示可以拆除的障碍,求解从起点到终点的最短路径。 思路: 本题中可以扩展的结点分为两类: (1)‘E’:通过需一个时间单位 (2)‘B’:通过需两个时间单位 利用优先队列,优先扩展用时最少的结点,其余操作与基础广搜相同。 代码实现: #inclu...

Keep eating codes! 307

STM32F407中文手册

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

poj2312 Battle City 【暴力 或 优先队列+BFS 或 BFS】

题意:M行N列的矩阵。Y:起点,T:终点。S、R不能走,走B花费2,走E花费1.求Y到T的最短时间。 三种解法。♪(^∇^*) //解法一:暴力 //157MS #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #incl...

dhe56357的博客 109

poj 2312 Battle City bfs +优先队列

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6496   Accepted: 2176 Description Many of us had played the game "Battle city" in our childhood,

小磊's blog 883

POJ 2312 Battle City BFS+优先队列

POJ 2312 Battle City博客搬新家,以后就是基本只在自己的独立博客进行更新,欢迎访问。http://zihengoi.cn题目描述:  题目链接:POJ 2312 Battle City题目大意:  坦克大战游戏中需要让坦克(Y)(Y)在给定的地图中到达指定的位置(T)(T)。其中移动至空地(E)(E)算一次操作,砖墙(B)(B)因为需要先打破再通过故算两次操作,金属墙和河不能通过。

Running Boy的AC Dream 496

POJ 2312 Battle City【Bfs+优先队列】

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8114   Accepted: 2716 Description Many of us had played the game "Battle city"

mengxiang000000 659

POJ 2312 Battle City 【BFS + 优先队列】

Many of us had played the game “Battle city” in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this game. Given a...

qq_42445959的博客 304

POJ 2312 Battle City (优先队列 + BFS)

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8127   Accepted: 2724 Description Many of us had played the game "Battle city" in our childhood,

MADE_Y 374

POJ 2312 Battle City 优先队列+bfs

Battle CityTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 8597 Accepted: 2882 DescriptionMany of us had played the game “Battle city” in our childhood, and some people (like me)

lixiyi的博客 335

【BFS+优先队列】Battle City(poj-2312)

原题链接点击打开链接 其实现在仔细想想,对初学者而言,在BFS和DFS中,还真是BFS学起来更为容易(至少我是这么认为)。BFS不需要层层递归,不需要考虑搜索路径不符合条件时应该如何变换。它只是一步一步的扫描,然后把相关信息归纳一下而已。我们需要的知识少许的STL知识就行了。 言归正传,这道题应该属于迷宫搜索题,而在搜索过程中,又要找出最少“消耗”的那一条路,从这点看,又有点像图论中的最短路了

Mr.ProphetK 690

POJ - 2312 Battle City BFS+优先队列

Battle City Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now.What we are discussing is a simple edition of this game. Given...

weixin_30951231的博客 132
上一篇: FZU 2168 防守阵地 I
下一篇: HDU 1242 Rescue(优先队列 + 多源BFS)
小爷永远不死
博客等级 码龄15年 58粉丝 363原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值