POJ 2312 Battle City ——————BFS

Codex 桌面端自定义模型列表为空 — 修复记录 摘要:Codex桌面端首次启动正常,但二次启动后出现中文界面且模型列表丢失。问题根源在于Electron的Chromium持久化状态损坏,导致UI渲染异常。解决方案包括:1) 将config.toml中的模型路径改为绝对路径;2) 删除损坏的状态文件.codex-global-state.json;3) 清除Chromium用户数据目录AppData\Roaming\Codex\web。验证显示修改后模型功能恢复正常,重装无效的原因是卸载未清除用户数据目录。 阅读详情

Language:Default
Battle City
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 10110Accepted: 3364

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. ![这里写图片描述](http://poj.org/images/2312_1.jpg)
What we are discussing is a simple edition of this game. Given a map that consists of empty spaces, rivers, steel walls and brick walls only. Your task is to get a bonus as soon as possible suppose that no enemies will disturb you (See the following picture). ![这里写图片描述](http://poj.org/images/2312_2.jpg)
Your tank can’t move through rivers or walls, but it can destroy brick walls by shooting. A brick wall will be turned into empty spaces when you hit it, however, if your shot hit a steel wall, there will be no damage to the wall. In each of your turns, you can choose to move to a neighboring (4 directions, not 8) empty space, or shoot in one of the four directions without a move. The shot will go ahead in that direction, until it go out of the map or hit a wall. If the shot hits a brick wall, the wall will disappear (i.e., in this turn). Well, given the description of a map, the positions of your tank and the target, how many turns will you take at least to arrive there?

Input

The input consists of several test cases. The first line of each test case contains two integers M and N (2 <= M, N <= 300). Each of the following M lines contains N uppercase letters, each of which is one of ‘Y’ (you), ‘T’ (target), ‘S’ (steel wall), ‘B’ (brick wall), ‘R’ (river) and ‘E’ (empty space). Both ‘Y’ and ‘T’ appear only once. A test case of M = N = 0 indicates the end of input, and should not be processed.

Output

For each test case, please output the turns you take at least in a separate line. If you can’t arrive at the target, output “-1” instead.

Sample Input

3 4
YBEB
EERE
SSTE
0 0

Sample Output

8

Source

POJ Monthly,鲁小石
—– BFS 简单题 —–
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN=309;
int n,m,stx,sty,edx,edy,ans;
char str[MAXN][MAXN];
bool vis[MAXN][MAXN];
int d[4][2]={0,1, 0,-1, 1,0, -1,0};
struct node{
    int x,y,step;
    node(){};
    node(int _x,int _y,int _step)
    {
        x=_x;y=_y;step=_step;
    }
    bool operator < (const node &b)const
    {
        return step>b.step;
    }
};

void bfs(int x,int y)
{
    memset(vis,0,sizeof(vis));
    priority_queue<node> que;
    node e1,e2;
    vis[x][y]=1;
    que.push(node(x,y,0));
    while(que.size())
    {
        e1=que.top();que.pop();
        if(str[e1.x][e1.y]=='T')
        {
            ans=e1.step;
            break;
        }
        for(int i=0;i<4;i++)
        {
            e2.x=e1.x+d[i][0];
            e2.y=e1.y+d[i][1];
            e2.step=e1.step+1;
            if(!vis[e2.x][e2.y] && 0<= e2.x && e2.x < n && 0 <= e2.y && e2.y <m && str[e2.x][e2.y]!='R' && str[e2.x][e2.y]!= 'S')
            {
                vis[e2.x][e2.y]=1;
                if(str[e2.x][e2.y]=='B') e2.step++;
                que.push(e2);
            }
        }
    }
}


int main()
{
    while(~scanf("%d %d",&n,&m)&&(n|m))
    {
        for(int i=0;i<n;i++)    scanf("%s",str[i]);
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
            {
                if(str[i][j]=='Y')
                {
                    stx=i;
                    sty=j;
                    break;
                }
            }
        ans=-1;
        bfs(stx,sty);
        printf("%d\n",ans);
    }
    return 0;
}

Probability and Statistics - 4th edition 立即下载

相关推荐

Toeplitz矩阵以及矩阵乘法FFT加速

Toeplitz矩阵以及矩阵乘法FFT加速 1.Toeplitz矩阵 托普利兹矩阵,简称为T型矩阵,它是由Bryc、Dembo、Jiang于2006年提出的。托普利兹矩阵的主对角线上的元素相等,平行于主对角线的线上的元素也相等;矩阵中的各元素关于次对角线对称,即T型矩阵为次对称矩阵。这里我们使用matlab中自带的函数生成一个toeplitz矩阵的例子: x=[1 2 3 4]; y=[1 5 6 7 8 9]; z=toeplitz(x,y); 我们可以得到一个这样的矩阵结果: 我们可以看到,其中x中

thlz 5069

【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

告别调参玄学:用 DINOv2 (ViT-S/ViT-G) 和 PCA 可视化,直观理解自监督特征

本文深入解析了DINOv2(ViT-S/ViT-G)模型在自监督学习中的特征提取机制,通过PCA降维技术实现特征空间的可视化。文章对比了不同规模模型的特征表达差异,并提供了PCA阈值调优和深度分析的实用技巧,帮助读者直观理解自监督学习的视觉密码。

weixin_42565865的博客 410

POJ 2312 Battle City 优先队列+BFS

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

Hackbuteer1的专栏 5532

SAP采购订单行项目增强实战:用BADI ME_GUI_PO_CUST添加自定义字段(避坑指南)

本文详细解析了如何通过BADI ME_GUI_PO_CUST在SAP采购订单行项目中添加自定义字段,包括技术架构理解、字段扩展步骤、自定义函数组创建及BADI实现。文章特别强调了避开官方文档未提及的陷阱,如字段映射限制和屏幕显示问题,并提供了高级优化技巧和性能建议。

weixin_30402343的博客 594

别再傻傻分不清!一文讲透电子产品‘冲击’与‘碰撞’试验的区别与选用(附GB/T 2423标准解读)

本文详细解析了电子产品可靠性测试中冲击与碰撞试验的核心区别与应用场景,结合GB/T 2423标准提供实用指南。冲击测试模拟瞬时高强度事件(如跌落),而碰撞测试针对重复性力学环境(如运输颠簸)。通过参数对比和标准解读,帮助研发人员精准选择测试方案,提升产品可靠性验证效率。

weixin_42665255的博客 267

poj2312 Battle City bfs

http://poj.org/problem?id=2312 Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6903   Accepted: 2336 Description Many of us had played the

746

海康工业相机 Could not find module MvCameraControl.dll(已解决)

【代码】海康摄像机 Could not find module MvCameraControl.dll(已解决)

hmbbpdx的博客 2223

poj2312Battle City BFS

题意: M行N列矩阵, 'Y'表示开始位置, 'T'表示目标位置, 从开始位置到目标位置至少需要走多少步,其中, 'S', 'R'表示不能走, 'B' 花费为2, 'E'花费为1. 思路:纯 BFS. 很久没写BFS, 刚写居然不知道从何下手... 1 #include <iostream> 2 #include <queue> 3 usi...

187

【教程】ENVI主成分分析详解

主成分分析(PCA)是一种统计方法,简而言之就是用几种特性去描述事物。每个事物都可以用不同的特性去进行表达,但这些特性一般而言是存在相互的融合和冗余,而用主成分分析方法将这些特性进行转换成不相关的新特性。 在ENVI软件中共提供了三种主成分分析方式分别为:(1)Forward PCA Rotation Existing Statistics(2)Forward PCA Rotation New Statistics and Rotate(3)Inverse PCA Rotati...

YW_remote的博客 1万+

3D打印开源硬件MKS Monster8 V2.0 原理图赏析--更新中

MKS MONSTER8 主板是创客基地为满足市场需求而推出的主板,可用于Voron 2.4机器安装,支Marlin 固件和Klipper固件,支持U盘打印(暂时只有Marlin固件支持),支持TMC驱动UART模式,它包含了3D打印机所需要的主要部件和接口,通过MCU集中控制,是一款功能强大的主板。下面详细分析一下。

我的专栏 7224

POJ 2312 Battle City (BFS)

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 game. ...

HPU_LY的博客 313

【VS开发】【DSP开发】WinDriver简介(或介绍)

WinDriver for Windows简化并自动化了用户模式Windows设备驱动程序的开发,支持设备包括PCI / CardBus / ISA/ PCI-104 / PCMCIA * / PMC / PCI-X 和 CompactPCI,无需DDK或内核级编程知识。关于USB设备驱动开发,请参见WinDriver USB for Windows。   WinDriver包含一系列

ZhangPY的专栏 1477

poj 2312 Battle City-bfs

题目自己看吧:http://poj.org/problem?id=2312 代码:   #include #include #include #include #include #include #include #include using namespace std; #define INF 1000000001 struct Point{ int x,y;

桑榆 614

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

poj2312——Battle City【BFS】

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9931   Accepted: 3301 Description Many of us had played the game "Battle city" in ...

xiang_hehe的博客 378

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

[算法] BFS : poj 2312 Battle City 示例

纪念第一次用 “优先队列”, 第一次知道 “方向数组” ! BFS : 谁出队就找谁的邻接点访问之并入队!#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <...

anchang7456的博客 169

POJ 2312 Battle City bfs宽搜

类似"罗密欧与朱丽叶"那题,宽搜搞定。 Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5858   Accepted: 1934 Description Many of us had played the game "Battle city"

zck921031的专栏 839

poj 2312 Battle City bfs

简单bfs #include #include #include #include #include using namespace std; int n, m; struct node{ int x, y, t; }st; #define N 305 int dir[4][2] = { 1, 0, -1, 0, 0, 1, 0, -1 }; int sx, sy, ex, ey;

uuuuuu 538

POJ 2312 Battle City 优先多列+bfs

来源:http://poj.org/problem?id=2312 题意:题目背景就是小时候玩的坦克大战,求从起点到终点最少需要多少步。已知S和R是不能走得,E是空的,可以走,B是砖,只有打掉后才可以通过。 思路:很容易看出来这是一道广搜的题目,但是因为走E和走B所需要的时间不一样,因此不能用普通的队列存点。因为对于走B来说,要先打掉砖才能通过,所以我们可以理解为走B需要两步,而走E是指需要1

1660

【POJ】2312-Battle City(优化的广度搜索BFS)

【POJ】2312-Battle City(优化的广度搜索BFS)使用了不完全的对拍来查错; 【题目链接】http://poj.org/problem?id=2312

xuziling_的博客 365

POJ 2312 Battle City(bfs)

Description 题目背景就是小时候玩的坦克大战,求从起点到终点最少需要多少步。已知S和R是不能走得,E是空的,可以走,B是砖,只有打掉后才可以通过 Input 多组用例,每组用例第一行为row和col表示迷宫行列数,然后是一个row*col矩阵表示迷宫,以0 0结束输入 Output 对于每组用例,若能到达终点则输出最短步数,否则输出-1 Sample Input 3 4

ZSQ 596

poj2312--Battle City(Bfs)

Battle CityTime Limit:1000MSMemory Limit:65536KTotal Submissions:7712Accepted:2582DescriptionMany of us had played the game "Battle city" in our childhood, and some people (like me) even ofte...

dixi7825的博客 122

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

POJ - 2312 Battle City —— bfs

题意: 从Y走到T的最短路径,走E和T需要一秒,B需要两秒,R和S不能走 思路: bfs一下,记录到每个点的最短路径长度 #include &lt;iostream&gt; #include &lt;queue&gt; #include &lt;cstring&gt; #include &lt;cstdio&gt; using namespace std; #define mod 100...

Lngxling的博客 285

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
上一篇: POJ 1426 Find The Multiple ——————DFS
下一篇: POJ 3984 迷宫问题 —————— BFS
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值