NYOJ-284 坦克大战

java坦克大战 java项目实战 坦克大战 eclipse工程文件 内含源码与素材(详见此:https://blog.youkuaiyun.com/hza419763578/article/details/80784360) 立即下载

坦克大战

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 3
描述
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 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). 

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?
输入
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.
输出
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.
样例输入
3 4
YBEB
EERE
SSTE
0 0
样例输出
8
来源
POJ
上传者

sadsad


思路:

        求最小步数, 方法: 广搜 + 优先队列;

        使用优先队列的原因在于 同样走一步, 破墙需要比空白多花一个单位的时间;


代码:

#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>

#define N 310

using namespace std;

struct Node{
	friend bool operator< (Node n1, Node n2){	//重载 '<'
        return n1.count > n2.count;
    }
	int x;
	int y;
	int count;
};

char map[N][N];
priority_queue<Node>q;						//优先队列
int fx[4][2] = {0,1,0,-1,1,0,-1,0};			//方向数组

void bfs();

int main()
{
	int m, n;
	while(1){
		while(!q.empty()) q.pop();
		scanf("%d%d", &m,&n);
		if(m == 0 && n == 0) break;
		int i, j;
		Node u;
		memset(map, 'R', sizeof(map));
		for(i = 1; i <= m; i ++){
			for(j = 1; j <= n; j++){
				scanf(" %c", &map[i][j]);
				if(map[i][j] == 'Y') {         //确定本身坐标
					u.x = i;
					u.y = j;
					u.count = 0;
					q.push(u);
					map[i][j] = 'R';		   //标记走过自身位置
				}
			}
		}
		q.push(u);
		bfs();
	}
	
	return 0;
}

void bfs()
{
	while(1){
		Node nw;

		for(int i = 0; i < 4; i ++){
			nw.x = q.top().x;				 //初始化
			nw.y = q.top().y;
			nw.count = q.top().count + 1;

			nw.x += fx[i][0];
			nw.y += fx[i][1];
			if(map[nw.x][nw.y] == 'E') q.push(nw);		//空白
			if(map[nw.x][nw.y] == 'B'){		//遇到墙
				nw.count += 1;
				q.push(nw); 
			}
			if(map[nw.x][nw.y] == 'T'){		//到达目标
				printf("%d\n", nw.count);
				return;
			}
			map[nw.x][nw.y] = 'R';			//标记走过
		}

		q.pop();
		if(q.empty()){
			printf("-1\n");
			return;
		}
	}
	
}                


手把手教你用神经网络优化电机控制:从Simulink仿真到实际部署 本文提供了一套完整的工程实践指南,详细讲解了如何将神经网络应用于电机控制,从Simulink仿真建模、轻量级网络设计,到关键的模型量化与代码生成,最终实现向DSP/FPGA硬件的实际部署。文章直面实时性、精度与资源限制等核心工程挑战,为工程师提供了从理论到落地的清晰路径和实用避坑策略。 阅读详情

相关推荐

MinerU与Docling:智能文档处理框架对比

本文对比分析了MinerU和Docling两大智能文档处理框架。MinerU专注于高精度PDF解析,采用多模态AI技术,在学术文献、金融报表等复杂文档处理上表现优异;Docling则定位企业级多格式文档处理平台,支持10+格式转换,更适合文档管理系统等场景。技术层面,MinerU基于VLM模型实现端到端处理,Docling采用插件化多后端架构。性能测试显示MinerU精度更高(95%+),但资源消耗较大;Docling处理速度更快(1-3秒/页),部署更灵活。

轩哥的个人研究和成长记录 1910

poj 2312( 搜索 )

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

jiakai0419的专栏 1248

在PLC中将十六进制数据转换为浮点数(通常遵循IEEE 754标准)需要理解数据存储格式,并按以下步骤操作:

通过以上步骤,您可以在PLC中实现十六进制到浮点数的转换。T DBD20 // 将数据传送到浮点数变量(如DB1.DBD20)指数位(8位):实际指数 = 存储值 - 127(偏移量)。:必须确认PLC的存储顺序(大端或小端),否则结果错误。将两个16位寄存器合并为32位数据,需注意。尾数位(23位):隐含前导1,实际值为。:确保32位数据在寄存器中连续且对齐。符号位(1位):0表示正,1表示负。:高位寄存器在前(如西门子PLC)。:低位寄存器在前(如三菱FX系列)。,误差因截断导致)。

K11mvp的博客 4418

【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

告别手动改图!用Python+PyWin32驱动SolidWorks,实现参数自动化修改(保姆级避坑指南)

本文详细介绍了如何利用Python和PyWin32驱动SolidWorks实现参数自动化修改,提供从环境配置到API连接的工业级解决方案。通过实战案例和避坑指南,帮助工程师高效搭建自动化脚本工作流,显著提升设计效率。

weixin_30614109的博客 742

把 sy-* 带进 ABAP CDS:ABAP 7.50 里的环境信息新姿势($session 与 @Environment.systemField 实战)

摘要:ABAP 7.50在CDS视图中引入两种获取环境信息的方式:1)直接使用$session会话变量读取用户、客户端和系统语言;2)通过@Environment.systemField注解参数,由Open SQL自动注入系统字段。$session方式简单但依赖Open SQL访问路径,非ABAP环境下可能失效;注解参数方案更工程化,依赖关系明确且支持测试。建议ABAP体系内优先使用$session,对外接口采用参数化方案。两种方式各有适用场景,正确选择可避免潜在风险。(148字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 152

POJ 2312 Battle City 【SPFA最短路详解】

Battle CityTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9444 Accepted: 3121DescriptionMany of us had played the game "Battle city" in our childhood, and some people (like me) even often p...

森林海的博客 338

【Windows Server 2019】活动目录 (Active Directory) ——将计算机加入域和脱离域

博文介绍了如何将计算机加入AD域和脱离AD域,包括加入域,验证客户机加入到域后的信息,使用域账户用户在客户机上登录,使用本地账户用户在计算机上登录,脱离域。

VMware, Windows, Linux, Cisco, Container, Kubernetes, Kali 6169

POJ2312 Battle City(BFS+优先队列)

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

Keep eating codes! 307

滤波算法实现大全——基于匀速直线运动模型的kalman滤波算法

滤波算法实现大全——基于匀速直线运动模型的kalman滤波算法

jane0819的博客 522

AIGC算法工程师面试八股文深度解析与进阶指南:揭秘Diffusion Models核心原理与实战技巧

总结来说,Cosine Noise Scheduler 的核心优势在于它能够更巧妙地平衡信号和噪声的比例,在扩散过程的早期阶段更长时间地保留原始图像的细节信息,从而为去噪模型提供一个更友好的学习环境,最终带来更优异的生成质量。🚀

FJN110的博客 345

(NYoj 284)坦克大战--裸BFS ,优先队列

坦克大战 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 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

STILLxjy 743

ROS从入门到精通0-4:VSCode 搭建 ROS 工程环境

为了提高开发效率,可以先安装集成开发工具和使用方便的工具,本教程用VSCode搭建ROS工程环境

FRIGIDWINTER的博客 1万+

nyoj 284 坦克大战

坦克大战 时间限制:1000 ms  |           内存限制:65535 KB 难度:3 描述 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 ar

世界很大 570

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

nyoj 284 坦克大战 简单搜索

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=284

MInt 918

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

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

NYOJ 284 坦克大战

坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 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 dis

阿金的ACM 688

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

nyoj 284 坦克大战(BFS)

问题 J: 坦克大战 时间限制: 1 Sec  内存限制: 64 MB 提交: 19  解决: 13 [提交][状态][讨论版] 题目描述 Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer n

BBHHTT的博客 471

nyoj 284 坦克大战

坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 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 discu

357

NYOJ 284 坦克大战(BFS)

题目链接:Click here~~ 好累啊,写篇博客歇歇。 题目背景很有趣,是大家小时候经常玩的坦克大战,哈哈。弱弱地表示本人小时候经常玩游戏机。 此题是在迷宫问题的基础上做了些改动,就是地图上能走的点可能耗费时间1,也可能耗费时间2。 那么,元素在出队列时,不能简单的按照以前的入队顺序出队了,而应该让时间最短的先出队, 这样就能够保证先入队的点一定是时间最短的,那么搜到终点时也时间

nyist_xiaod 1273

nyoj-284-坦克大战

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

梦里回忆-专栏 822

nyoj 284 坦克大战【bfs】

坦克大战 时间限制:1000ms | 内存限制:65535KB 难度:3 描述 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 discussi...

weixin_30263277的博客 156

NYOJ284坦克大战

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=284 BFS求最短路,这个题走到‘B’点是要花费2个时间,'E‘是1个时间,所以要用一个优先队列,优先级就是花费小的先出队,其余的就是模板了。 代码: #include #include #include using namespace std; #

奋斗的Die Young 554

坦克大战(nyoj284)

题目大体意思就是,求从地图上的Y走到T的最小步数,其中S和R不能走,B要走两步,E要走一步。 测试输入: 3 4 YBEB EERE SSTE 0 0 测试输出: 8 这个题要用优先队列,不用的话没有办法保证所求的步数是最小的。 我也查了一些关于优先队列的资料,做以下整理: 在优先队列中,优先级高的元素先出队列。 标准库默认使用元素类型的

23333333 1330
上一篇: NYOJ-221 Tree(前序中序推后序)
下一篇: NYOJ-287 Radar(贪心)
tbl00c
博客等级 码龄13年 21粉丝 91原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值