1G: bfs

本文探讨了一款RPG游戏中,玩家如何在怪物威胁下,从起点安全到达终点的最短路径问题。通过BFS算法解决,考虑到地图大小和怪物的危险范围,实现了有效的路径寻找。

传送门

题目

You play a new RPG. The world map in it is represented by a grid of n × m cells. Any playing character staying in some cell can move from this cell in four directions — to the cells to the left, right, forward and back, but not leaving the world map.
Monsters live in some cells. If at some moment of time you are in the cell which is reachable by some monster in d steps or less, he immediately runs to you and kills you.
You have to get alive from one cell of game field to another. Determine whether it is possible and if yes, find the minimal number of steps required to do it.InputThe first line contains three non-negative integers n, m and d (2 ≤ n·m ≤ 200000, 0 ≤ d ≤ 200000) — the size of the map and the maximal distance at which monsters are dangerous.
Each of the next n lines contains m characters. These characters can be equal to «.», «M», «S» and «F», which denote empty cell, cell with monster, start cell and finish cell, correspondingly. Start and finish cells are empty and are presented in the input exactly once.OutputIf it is possible to get alive from start cell to finish cell, output minimal number of steps required to do it. Otherwise, output «-1».Examples

Input

5 7 1
S.M...M
.......
.......
M...M..
......F




Output

12




Input

7 6 2
S.....
...M..
......
.....M
......
M.....
.....F




Output

11




Input

7 6 2
S.....
...M..
......
......
.....M
M.....
.....F




Output

-1




Input

4 4 2
M...
.S..
....
...F




Output

-1

题目翻译

您在玩一个新的RPG。其中的世界地图由n×m个单元的网格表示。停留在某个单元格中的任何游戏角色都可以从该单元格向四个方向移动-移至左侧,右侧,向前和向后的单元格,但不会离开世界地图。怪物生活在一些细胞中。如果在某个时刻,您处于某个怪物可以d步或更短距离到达的牢房中,他会立即冲向您并杀死您。您必须从一个游戏领域的另一个单元活下来。确定是否可能,如果可以,请找到执行此操作所需的最少步骤。输入值第一行包含三个非负整数n,m和d(2≤n·m≤200000,0≤d≤200000)—地图的大小和怪物危险的最大距离。接下来的n行中的每行包含m个字符。这些字符可以等于«。»,«M»,«S»和«F»,分别表示空单元格,带有怪兽的单元格,开始单元格和结束单元格。开始和结束单元格为空,并且在输入中仅显示一次。输出量如果可以从起始单元格到结束单元格恢复活力,则输出执行此步骤所需的最少步骤。否则,输出«-1»。

解法

求最少步数,显然是用bfs,值得一提的是它给定的n和m的范围是2≤n·m≤200000,所以直接开_map[200000][200000]会炸, 可以开个一维数组,坐标转化一下就好了,或者在输入n和m后再创建数组
(反正200000又不会爆)

代码

#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

int dir[4][2] = {1,0, 0,1, -1,0, 0,-1};
int main()
{
	int n, m, d;
    	cin >> n >> m >> d;
     	char _map[n+5][m+5];
	bool vis[n+5][m+5];
	memset(vis, 0, sizeof(vis));
 	memset(_map, 0, sizeof(_map));
	
	 for(int i=1; i<=n; ++i) {
 		 for(int j=1; j<=m; ++j) {
  			 cin >> _map[i][j];
 	 	}
	 }
	 queue <int> xx, yy, dd;
	 int sx, sy, gx, gy;
	 for(int i=1; i<=n; ++i) {
 	 	for(int j=1; j<=m; ++j) {
  	 		if(_map[i][j]=='S') {
  	  			sx = i;
  	  			sy = j;
  	 		}
  	 		if(_map[i][j]=='F') {
		  	  gx = i;
		  	  gy = j;
		  	 }
		  	if(_map[i][j] =='M') {
				    xx.push(i);
				    yy.push(j);
				    vis[i][j] = 1;
				    dd.push(d);
			 }
		}
	 }

	return 0;
}
内容概要:本文介绍了基于改进Retinex算法的视频图像增强技术研究,并提供了相应的Matlab代码实现。Retinex理论源于人类视觉系统对光照变化的适应性,通过分离图像的照度与反射分量,有效提升图像的亮度、对比度和色彩保真度。文中所提出的改进算法旨在克服传统Retinex方法中存在的光晕伪影、噪声放大和计算复杂等问题,可能引入了如多尺度分解、颜色校正或自适应滤波等优化策略,从而实现更自然、清晰的图像增强效果。该研究特别适用于低光照、雾霾、水下拍摄等恶劣成像条件下的视频与图像处理,提升后续视觉分析的准确性。; 适合人群:具备一定图像处理基础和Matlab编程经验的科研人员、研究生及工程技术人员,尤其是从事计算机视觉、视频监控、遥感影像、医学影像或无人机视觉导航等领域研究的专业人士。; 使用场景及目标:① 解决实际应用中因光照不足或环境干扰导致的图像质量下降问题;② 学习和掌握Retinex算法的核心思想及其改进方法;③ 获取可直接运行和调试的Matlab代码,作为相关课题研究或项目开发的技术参考。; 阅读建议:此资源以Matlab代码实现为核心,建议读者在阅读时结合代码逐行分析,理解算法的每一步实现细节。同时,应尝试使用不同的测试图像进行实验,调整算法参数,观察增强效果的变化,从而深入理解算法的性能特点和优化方向。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值