当前位置:网站首页>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,所以就换了一个方法。
代码:
边栏推荐
- MYSQL误删数据恢复
- Real-time data warehouse practice of Baidu user product flow and batch integration
- 娄底疾控中心实验室设计理念说明
- Prada, big show?In the yuan in the universe that!
- Jenkins修改端口号, jenkins容器修改默认端口号
- 鸿蒙开发从hello world开始
- 【百度统计】用户行为分析
- Loudi Cosmetics Laboratory Construction Planning Concept
- Detailed explanation of es6-promise object
- CodeForces - 834C
猜你喜欢
2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences
金山云要飘到哪里?
wirshark 常用操作及 tcp 三次握手过程实例分析
【百度统计】用户行为分析
11 + chrome advanced debugging skills, learn to direct efficiency increases by 666%
Polygon zkEVM工具——PIL和CIRCOM
Detailed explanation of es6-promise object
LeetCode中等题之比较版本号
Real-time data warehouse practice of Baidu user product flow and batch integration
Redis上云迁移实践
随机推荐
phpstrom 快速注释:
wirshark 常用操作及 tcp 三次握手过程实例分析
想通这点,治好 AI 打工人的精神内耗
C#WPF 图片在显示时没有问题,但在运行时图片显示不出来的解决
一个 CRM One Order Application log 的单元测试报表
代码随想录笔记_动态规划_70爬楼梯
C# error The 'xmins' attribute is not supported in this context
表中存在多个索引问题? - 聚集索引,回表,覆盖索引
Redis上云迁移实践
娄底干细胞制备实验室建设须知要求
一种能让大型数据聚类快2000倍的方法,真不戳
Loudi Sewage Treatment Plant Laboratory Construction Management
CodeForces-834C
娄底污水处理厂实验室建设管理
MYSQL误删数据恢复
【学习笔记】Redis的持久化
Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
Interface Automation Testing Basics
【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解
金山云要飘到哪里?