当前位置:网站首页>Borg Maze (bfs+最小生成树)
Borg Maze (bfs+最小生成树)
2022-08-10 12:52:00 【51CTO】
Problem Description
The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collective is the term used to describe the group consciousness of the Borg civilization. Each Borg individual is linked to the collective by a sophisticated subspace network that insures each member is given constant supervision and guidance.
Your task is to help the Borg (yes, really) by developing a program which helps the Borg to estimate the minimal cost of scanning a maze for the assimilation of aliens hiding in the maze, by moving in north, west, east, and south steps. The tricky thing is that the beginning of the search is conducted by a large group of over 100 individuals. Whenever an alien is assimilated, or at the beginning of the search, the group may split in two or more groups (but their consciousness is still collective.). The cost of searching a maze is definied as the total distance covered by all the groups involved in the search together. That is, if the original group walks five steps, then splits into two groups each walking three steps, the total distance is 11=5+3+3.
Input
On the first line of input there is one integer, N <= 50, giving the number of test cases in the input. Each test case starts with a line containg two integers x, y such that 1 <= x,y <= 50. After this, y lines follow, each which x characters. For each character, a space `` '' stands for an open space, a hash mark ``#'' stands for an obstructing wall, the capital letter ``A'' stand for an alien, and the capital letter ``S'' stands for the start of the search. The perimeter of the maze is always closed, i.e., there is no way to get out from the coordinate of the ``S''. At most 100 aliens are present in the maze, and everyone is reachable.
Output
For every test case, output one line containing the minimal cost of a succesful search of the maze leaving no aliens alive.
Sample Input
Sample Output
题目大概:
在迷宫里抓住所有外星人的最佳方式。
思路:
用bfs()求出所有点(包括S和所有A)之间的最短距离,再用prim最小生成树求出最短路的距离。
这个题的输入非常坑,错了几次都是在那里,首先在输入地图前,有一个换行符,在输入数据中间后面还有空格,我用getchar()试过,是wr,所以就换了一个方法。
代码:
边栏推荐
- 专有云ABC Stack,真正的实力派!
- Jiugongge lottery animation
- bgp dual plane experiment routing strategy to control traffic
- jenkins数据迁移和备份
- 商汤自研机械臂,首款产品是AI下棋机器人:还请郭晶晶作代言
- 22家!北京昌平区通报存在食品安全问题餐饮服务企业
- 22!Beijing Changping District notified catering service enterprises with food safety problems
- 神经网络可视化有3D版本了,美到沦陷!(已开源)
- Inventory of Loudi Agricultural Products Inspection Laboratory Construction Guidelines
- 3DS MAX 批量导出文件脚本 MAXScript 带界面
猜你喜欢

BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection 论文笔记

生成树协议STP(Spanning Tree Protocol)

燃炸!字节跳动成功上岸,只因刷爆LeetCode算法面试题

交换机的基础知识

把相亲角搬到海外,不愧是咱爸妈

iTextSharp操作PDF

MySQL面试题——MySQL常见查询
![ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]](/img/da/b49d7ba845c351cefc4efc174de995.png)
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]

Jenkins修改默认主目录

ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版
随机推荐
协程与任务
LeetCode中等题之比较版本号
Merge similar items in LeetCode simple questions
Codeforces Round #276 (Div. 1) B. Maximum Value
Jenkins修改端口号, jenkins容器修改默认端口号
瑞幸「翻身」?恐言之尚早
3DS MAX 批量导出文件脚本 MAXScript 带界面
教育Codeforces轮41(额定Div。2)大肠Tufurama
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
浙大、阿里提出DictBERT,字典描述知识增强的预训练语言模型
Requirements for the construction of Loudi stem cell preparation laboratory
线代 | 秒杀方法与技巧
LeetCode简单题之合并相似的物品
【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding
用低代码驱动IT现代化
没有接班人,格力只剩“明珠精选”
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
[Study Notes] Persistence of Redis
22家!北京昌平区通报存在食品安全问题餐饮服务企业
A unit test report for CRM One Order Application log