当前位置:网站首页>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,所以就换了一个方法。
代码:
边栏推荐
- Real-time data warehouse practice of Baidu user product flow and batch integration
- 娄底妆品实验室建设规划构思
- C#中导入其它自定义的命名空间
- I would like to ask the big guys, how to solve this error when cdc oracle initializes a 3 million table task running
- Ethernet channel Ethernet channel
- Ethernet channel 以太信道
- rpn:def concat_box_prediction_layers
- Redis 定长队列的探索和实践
- C#WPF 图片在显示时没有问题,但在运行时图片显示不出来的解决
- 2022-08-09:以下go语言代码输出什么?A:否,会 panic;B:是,能正确运行;C:不清楚,看投票结果。 package main import ( “fmt“ “syn
猜你喜欢

Ethernet channel Ethernet channel

神经网络可视化有3D版本了,美到沦陷!(已开源)

Jenkins修改默认主目录

【百度统计】用户行为分析

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

Jiugongge lottery animation

一个 CRM One Order Application log 的单元测试报表
![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]

广东10个项目入选工信部2021年物联网示范项目名单

没有接班人,格力只剩“明珠精选”
随机推荐
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection 论文笔记
CodeForces - 834C
【数字IC验证进阶】SoC系统验证和IP模块验证的区别及侧重点分析
AtCoder初学者比赛077 D -小多
把相亲角搬到海外,不愧是咱爸妈
需要被记录的OpenStack相关的命令_自己用
Basic knowledge of switches
iTextSharp操作PDF
Open Office XML 格式里如何描述多段具有不同字体设置的段落
LeetCode中等题之颠倒字符串中的单词
代码随想录笔记_动态规划_70爬楼梯
A detailed explanation of implementation api embed
ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]
shell:常用小工具(sort、uniq、tr、cut)
山水的高度
Comparison version number of middle questions in LeetCode
娄底干细胞制备实验室建设须知要求
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
Detailed explanation of es6-promise object
C# error The 'xmins' attribute is not supported in this context