博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3026 Borg Maze
阅读量:6197 次
发布时间:2019-06-21

本文共 3119 字,大约阅读时间需要 10 分钟。

Borg Maze
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7998   Accepted: 2675

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

26 5##### #A#A### # A##S  ####### 7 7#####  #AAA####    A## S ####     ##AAA########

Sample Output

811

最小生成树问题,主要是要求出点点距离,即字母间边权。这里用BFS求出了边权,用prim算法求出了最小生成树路径。

AC代码例如以下:

#include
#include
#include
#include
#define inf 100000using namespace std;char map[60][60];int vis[60][60],v[60][60];int n,m,tt,ans;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};struct H{ int h,z;}a[10005];int w[251][251],lc[251],vv[60][60];//W是边权记录,LCprim算法运用,VV记录第几个字母的坐标struct HH{ int h,z,st;};int bfs(int h,int z){ int i; v[h][z]=1; queue
q; HH a,b,c; a.h=h; a.z=z; a.st=0; q.push(a); while(!q.empty()) { b=q.front(); q.pop(); if(vv[b.h][b.z])//统计边权 { w[vv[h][z]][vv[b.h][b.z]]=b.st; w[vv[b.h][b.z]][vv[h][z]]=b.st; //cout<
<<" "<
<<" "<
<
=0&&c.h
=0&&c.z
w[id][i]) lc[i]=w[id][i]; } }}int main(){ int i,j,l; int t; char c[10]; scanf("%d",&t); gets(c); while(t--) { tt=1; memset(vis,0,sizeof vis ); cin>>m>>n; gets(c); for(i=0;i
 

转载地址:http://pqjca.baihongyu.com/

你可能感兴趣的文章
Java中public,private,final,static等概念的解读
查看>>
nexus-2.5安装(图文)
查看>>
4行CSS实现表格内容超过一行的部分,用省略号代替
查看>>
Ubuntu下LAMP环境搭建 Apache、MySQL、PHP
查看>>
记一次性能压测的问题排查过程
查看>>
GlbLib函数库手册
查看>>
spring security3.x学习(2)_认证和授权&运行第一个项目
查看>>
做程序员10年有感,程序员必须要懂的---转自java诺曼底_kleen
查看>>
使用opencv显示一幅图像的每个像素值
查看>>
web-socket地址存储
查看>>
JQ实现鼠标经过提示效果
查看>>
Code::Blocks使用教程
查看>>
activeMQ Topic与队列2种消息发送模式
查看>>
Linux基础 -- 文件系统操作与磁盘管理
查看>>
用SSH连接远端服务器
查看>>
理解java中反射,区别Class.forName(),Class.forName().instance() ,new
查看>>
svn: Server sent unexpected return value (502 B...
查看>>
【工具使用系列】关于 MATLAB 遗传算法与直接搜索工具箱,你需要知道的事
查看>>
Spring MVC Controller中解析GET方式的中文参数会乱码的问题
查看>>
django集成已有的数据库和应用
查看>>