当前位置:网站首页>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,所以就换了一个方法。
代码:
边栏推荐
- es6-promise对象详解
- 递归递推之Fighting_小银考呀考不过四级
- ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]
- 海外邮件发送指南(二)
- CodeForces - 834C
- rpn:def concat_box_prediction_layers
- Loudi Center for Disease Control and Prevention Laboratory Design Concept Description
- AtCoder Beginner Contest 077 D - Small Multiple
- The recursive recursive Fighting_ silver study ah but level 4
- 友邦人寿可观测体系设计与落地
猜你喜欢
Ethernet channel 以太信道
Prada, big show?In the yuan in the universe that!
bgp dual plane experiment routing strategy to control traffic
Shell:数组
【百度统计】用户行为分析
没有接班人,格力只剩“明珠精选”
Polygon zkEVM工具——PIL和CIRCOM
Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
数字藏品,“赌”字当头
Real-time data warehouse practice of Baidu user product flow and batch integration
随机推荐
mSystems | 中农汪杰组揭示影响土壤“塑料际”微生物群落的机制
G1和CMS的三色标记法及漏标问题
CodeForces - 834C
娄底石油化工实验设计、建设规划概述
LeetCode中等题之搜索二维矩阵
友邦人寿可观测体系设计与落地
九宫格抽奖动效
How to describe multiple paragraphs with different font settings in Open Office XML format
C#中导入其它自定义的命名空间
想问下大佬们 ,cdc oracle初始化一张300万的表任务运行着后面就这个错 怎么解决哇
[Study Notes] Persistence of Redis
中科院深圳先进技术院合成所赵国屏院士组2022年招聘启事
Basic knowledge of switches
Redis 定长队列的探索和实践
【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding
山水的高度
OpenStack-related commands that need to be recorded _ self-use
LeetCode·每日一题·640.求解方程·模拟构造
【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read