ACM: 图论题 BFS + STL + priority…
来源:互联网 发布:淘宝网店加盟哪家好 编辑:程序博客网 时间:2024/05/05 19:22
Description
The Borg is an immensely powerful race of enhanced humanoids fromthe delta quadrant of the galaxy. The Borg collective is the termused to describe the group consciousness of the Borg civilization.Each Borg individual is linked to the collective by a sophisticatedsubspace network that insures each member is given constantsupervision and guidance.
Your task is to help the Borg (yes, really) by developing a programwhich helps the Borg to estimate the minimal cost of scanning amaze for the assimilation of aliens hiding in the maze, by movingin north, west, east, and south steps. The tricky thing is that thebeginning of the search is conducted by a large group of over 100individuals. Whenever an alien is assimilated, or at the beginningof the search, the group may split in two or more groups (but theirconsciousness is still collective.). The cost of searching a mazeis definied as the total distance covered by all the groupsinvolved in the search together. That is, if the original groupwalks five steps, then splits into two groups each walking threesteps, 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 suchthat 1 <= x,y <= 50. After this, ylines follow, each which x characters. For each character, a space`` '' stands for an open space, a hash mark ``#'' stands for anobstructing wall, the capital letter ``A'' stand for an alien, andthe capital letter ``S'' stands for the start of the search. Theperimeter of the maze is always closed, i.e., there is no way toget out from the coordinate of the ``S''. At most 100 aliens arepresent in the maze, and everyone is reachable.
Output
For every test case, output one line containing the minimal cost ofa succesful search of the maze leaving no aliens alive.
Sample Input
2
6 5
#####
#A#A##
# # A#
#S
#####
7 7
#####
#AAA###
#
# S ###
#
#AAA###
#####
Sample Output
8
11
题意: 从 S 点出发 , 寻找外星人 , 可以分组进行搜索 , 分组可以是一开始就分组 , 或者是找到一个
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
#define MAX 53
typedef struct priority_node
{
}PNODE;
typedef struct node
{
}NODE;
typedef priority_queue<PNODE>PQU;
typedef queue<NODE> QU;
int dir[4][2] = { {0,1} , {0,-1} , {1,0} , {-1,0} };
int n , m;
char map[MAX][MAX];
NODE cur , next;
PNODE pcur;
int find(int su,int sv)
{