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

UE5与Cesium for Unreal结合:打造高效离线地图解决方案 本文详细介绍了如何利用UE5与Cesium for Unreal结合打造高效离线地图解决方案,特别适用于数字孪生、军事仿真等网络不稳定场景。通过优化配置、数据处理和性能调优,实现TB级地形数据的流畅渲染,并结合实战案例展示了在油田巡检等复杂环境中的应用效果。 阅读详情

题目链接: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;
}


数学建模:相关性分析学习——皮尔逊(pearson)相关系数与斯皮尔曼(spearman)相关系数 相关性分析:求解相关系数并绘制热力图进行对比 阅读详情

相关推荐

Lakes.AERMOD.View.v8.9.0 1CD大气扩散模型软件包

Lakes.AERMOD.View.v8.9.0 1CD大气扩散模型软件包 Lakes Environmental ARTM View v1.4.2 1CD放射物扩散模拟模型 Aermod View是一套完整的、功能强大的大气扩散模型软件包,并将美国EPA指定的大气扩散模型(如下)完美的集成成为一个综合的操作平 台: - AERMOD 电话TEL:18980583122  客服 QQ:11

yyii0000的博客 4001

POJ 2312 Battle City 优先队列+BFS

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

Hackbuteer1的专栏 5532

高效 DEM 拼接

通过以上步骤的系统实施,能够实现高效、准确的大型地理信息系统 DEM 数据拼接,满足复杂和大规模项目的应用需求。

llhllq2015的博客 1035

【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

Welch 方法详解:一种经典而实用的功率谱密度估计方法

在信号处理领域,谱分析是用于分析信号频率内容的强大工具。Welch方法是现代谱分析中一种广泛使用的功率谱密度估计技术,由Peter D. Welch在1967年提出。它通过对信号进行分段、加窗和平均化处理,提供了一种平滑且稳定的频谱估计方法。Welch方法通过将信号分成多个重叠的段,每段应用窗函数,然后计算每段的周期图,最后对所有周期图进行平均化,得到平滑的功率谱密度估计。welch_psd函数接收信号x、采样频率fs、每段的样本数N、重叠样本数overlap和窗函数类型window。

DuHz的博客 7060

别再死记硬背了!用Amesim HCD库亲手搭建单向阀、锥阀、球阀模型(附详细参数设置)

本文详细介绍了如何使用Amesim HCD库从零构建单向阀、锥阀和球阀的仿真模型,帮助工程师摆脱死记硬背,掌握物理建模的核心技巧。通过实战案例和参数设置指南,读者将学会如何优化阀门动态响应、验证流量特性以及处理旋转运动等独特挑战,提升液压系统设计效率。

weixin_29248611的博客 501

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

把STM32MP135当单片机玩:实战SD卡脱机运行LED程序(基于MP135DK开发板)

本文详细介绍了如何在STM32MP135开发板上实现SD卡脱机运行LED程序,通过裸机开发方式(Bare Metal)利用HAL库完成GPIO控制,并解析了SD卡启动流程。内容涵盖工程创建、代码编写、SD卡烧录及常见问题排查,为开发者提供了一种高性能单片机开发方案。

weixin_33734785的博客 242

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

香橙派5玩转SATA SSD:一个被忽略的overlays配置项,让你的Ubuntu系统飞起来

本文详细介绍了如何在香橙派5上通过配置`overlays=ssd-sata`启用SATA SSD作为系统启动盘,大幅提升Ubuntu系统的性能。文章深入解析了设备树覆盖的工作原理,提供了完整的配置流程和性能优化建议,帮助开发者充分发挥香橙派5的硬件潜力。

weixin_30787531的博客 220

48、住宅抵押贷款支持证券的定价、风险评估与结构化设计

本文深入探讨了住宅抵押贷款支持证券(RMBS)的定价、风险评估与结构化设计。内容涵盖提高定价准确性的方差缩减方法,如准蒙特卡罗序列的应用;分析RMBS面临的利率风险、信用风险和模型风险,并提出相应的度量与应对策略;介绍利用动态规划优化CMO分层结构以最大化发行利润的方法。同时总结了RMBS的基本类型、定价流程及市场发展趋势,为投资者和发行人提供全面的决策支持。

quiet的专栏 154

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

鸿蒙开发实战项目(四十七):图片编辑(ArkTS)

本篇Codelab主要介绍如何基于图片编解码,实现图片编辑。图片的解码。使用PixelMap进行图片编辑,如裁剪、旋转、亮度、透明度、饱和度等。图片的编码。

斌擎科技 1586

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

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

dianchunhui2654的博客 153

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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

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

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

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、付费专栏及课程。

余额充值