hud 1242 Rescue

2024-04-02 17:08
文章标签 1242 rescue hud

本文主要是介绍hud 1242 Rescue,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这道题是一道广度的裸题,套模版,最重要的是要比较距离的大小,因为这道题中不是移动每个点都是1,当遇到的是狱警'x'的时候距离要+2,因此可能出现移动次数多但是移动距离小的可能,所以要加上比较

used[xx][yy] = true;

if(map[xx][yy] == 'x')
if(step[xx][yy] > step[x1][y1]+2)
step[xx][yy] = step[x1][y1] + 2;
else
continue;
else
if(step[xx][yy] > step[x1][y1]+1)
step[xx][yy] = step[x1][y1]+1;
else

continue;

然后就是代码了。

#include <iostream>
#include <string>
#include <queue>


using std::string; using std::queue;
using std::cin; using std::cout;
using std::endl; 
char map[250][250];
int move[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
bool used[250][250];
int step[250][250];
int dis;
int n,m;
queue<int> q;


void bfs(int x1,int y1)
{
while(!q.empty())//清空
q.pop();


memset(used,false,sizeof(used));
memset(step,10000,sizeof(step));


int u = x1*m+y1;


q.push(u);
used[x1][y1] = true;
step[x1][y1] = 0;


while(!q.empty())
{
u = q.front();
q.pop();
x1 = u/m;
y1 = u%m;
for(int i = 0;i < 4;i++)
{
int xx = x1+move[i][0];
int yy = y1+move[i][1];
if(xx >= n||yy >= m||yy<0||xx<0||map[xx][yy] == '#')
continue;


used[xx][yy] = true;
if(map[xx][yy] == 'x')
if(step[xx][yy] > step[x1][y1]+2)
step[xx][yy] = step[x1][y1] + 2;
else
continue;
else
if(step[xx][yy] > step[x1][y1]+1)
step[xx][yy] = step[x1][y1]+1;
else
continue;


if(map[xx][yy] == 'a')
{
if(step[xx][yy] < dis)
dis = step[xx][yy];
return;
}
q.push(xx*m+yy);
}
}
}


int main()
{
while(cin>>n>>m)
{
for(int i = 0;i < n;i++)
for(int k = 0;k < m;k++)
cin>>map[i][k];


dis = 0xffffff;
//找到每个朋友的位置;
for(int i = 0;i < n;i++)
{
for(int k = 0;k < m;k++)
if(map[i][k] == 'r')
{
int x = i;
int y = k;
bfs(x,y);
}
}


if(dis == 0xffffff)
cout << "Poor ANGEL has to stay in the prison all his life."<<endl;
else
   cout << dis <<endl;
}
return 0;
}

这篇关于hud 1242 Rescue的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/870563

相关文章

迈巴赫S480升级增强现实AR抬头显示hud比普通抬头显示HUD更好用吗

增强AR实景抬头显示HUD(Augmented Reality Head-Up Display)是一种更高级的驾驶辅助技术,相比于普通抬头显示HUD,它提供了更丰富、更具沉浸感的驾驶体验。以下是它比普通抬头显示HUD多的一些功能: • 信息呈现方式:普通抬头显示HUD通常只能显示简单的文字和图标,而增强AR实景抬头显示HUD可以在驾驶员的视线范围内呈现更多的信息,并将其与实际道路场景进行融合

mondo rescue 备份centos

Mondo Rescue的官方网站: http://www.mondorescue.org/ 下面介绍安装mondo rescure对系统进行备份与恢复 1、在线安装 1)CentOS yum源配置 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repocurl -o /et

HDU 1242 广搜模板

广搜模板 #include "stdio.h"#include "string.h"#include "math.h"#include "queue"using namespace std;struct node{int x,y,step;friend bool operator<(node n1,node n2){return n2.step<n1.step;}};int

奔驰EQS SUV升级增强现实AR抬头显示HUD香氛系统

增强AR实景抬头显示HUD(Augmented Reality Head-Up Display)是一种更高级的驾驶辅助技术,相比于普通抬头显示HUD,它提供了更丰富、更具沉浸感的驾驶体验。以下是它比普通抬头显示HUD多的一些功能: • 信息呈现方式:普通抬头显示HUD通常只能显示简单的文字和图标,而增强AR实景抬头显示HUD可以在驾驶员的视线范围内呈现更多的信息,并将其与实际道路场景进行融合,使

车载导航曾经的王者,跌倒之后,欲借AR-HUD重新归来

电子发烧友网报道(文/莫婷婷)汽车智能化加速汽车座舱的演变,从传统座舱到智能座舱,功能不断集中,系统生态开始兼容、适配,智能座舱时代已经正式到来。一个新的时代来临,是进还是守? 如果以守成定输赢,那么凯立德或许就是在汽车智能化过程中被击败的巨头。目前,凯立德官网显示,公司仍在升级服务。与互联网浪潮擦肩而过,如何抓住智能座舱机遇成为凯立德以及其他芯片厂商、零部件供应商、解决方案商的挑战。

hud-2191多重背包问题

#include "stdio.h"#include "string.h"int p[105],h[105],c[105]; //价钱 重量 袋数int dp[105];int n;void CompletePacc(int p,int h) //第i种大米价格 第i种大米重量{int i;for(i=p;i<=n;i++)if(dp[i]<dp[i-p]+h) {dp[

HDU 1242 Rescue营救 BFS算法

题目链接:HDU 1242 Rescue营救 Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16524    Accepted Submission(s): 5997 Problem Descript

关于ubuntu安装之后系统grub被破坏了之后进行修复的总结(error:file not found。 grub rescue)

头几天在电脑上面安装双系统,在安装了windows后安装ubuntu来玩玩,结果当我把ubuntu安装成功的时候,从新启动电脑出现了如下的界面:Grub loading!welcome to Grub!error :file not found!  Entering rescure mode>当出现上面的情况的时候我上网查资料知道了是grub被破坏了,花了很长的时间最终把这个问题解决了,下面贴出

HUD 2955 Robberies [0-1背包的简单转化]

/*Hud 2955 Robberies简单的0-1背包转换.由此题,抽象的事物也可以相当形象的解释.形象的解释,看以下注释.*/#include<stdio.h>#include<string.h>#define max(a,b) a>b?a:bmain(){int T;scanf("%d",&T);while(T--){int i,n,v[105],V=0;double p,w[1

Hud 1874 畅通工程续[基础最短路(Dijsktra)]

第一次的最短路,还可以吧!经过别人的提醒2A. 题目链接:点击打开链接 #include<cstdio>#include<cstring>using namespace std;const int N=205;const int INF=0xffffff;int Map[N][N];int n,m,dis[N];bool vis[N];void Init(){for(in