Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7722 Accepted: 2592
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.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
2 6 5 ##### #A#A## # # A# #S ## ##### 7 7 ##### #AAA### # A# # S ### # # #AAA### #####
Sample Output
8 11
最小生成樹+bfs(求個點之間距離)
注意數組稍微開大一點,還有空格問題。。
#include"stdio.h" #include"string.h" #include"queue" using namespace std; #define N 200 //N為100就wrong了 #define M 200 const int inf=10000; int map[N][N]; //記錄個點之間距離 char str[N][N]; int row,col; //行和列 int dx[4]={0,0,-1,1}; int dy[4]={1,-1,0,0}; struct node { int x,y,t; friend bool operator<(node a,node b) { //距離短的優先級高 return a.t>b.t; } }f[M]; int judge(int x,int y) { if(x>=0&&x=0&&y
q; node cur,next; cur.x=f[index].x; cur.y=f[index].y; cur.t=0; q.push(cur); memset(mark,0,sizeof(mark)); mark[cur.x][cur.y]=1; while(!q.empty()) { cur=q.top(); q.pop(); for(i=0;i map[index][i]) dis[i]=map[index][i]; } return 0; } int main() { int T,i,j,n; char temp[200]; scanf("%d",&T); while(T--) { scanf("%d%d",&col,&row); gets(temp); //空格會有多個 for(i=0;i |