题干:

The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It is called 4DAir, and comes in four types. Each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the earth. The four types correspond to antennas operating in the directions north, west, south, and east, respectively. Below is an example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ellipses covering them. 
 
Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered? 
 

Input

On the first row of input is a single positive integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing two positive integers h and w, with 1 <= h <= 40 and 0 < w <= 10. Thereafter is a matrix presented, describing the points of interest in Sweden in the form of h lines, each containing w characters from the set ['*','o']. A '*'-character symbolises a point of interest, whereas a 'o'-character represents open space. 
 

Output

For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.

Sample Input

2
7 9
ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo
10 1
*
*
*
o
*
*
*
*
*
*

Sample Output

17
5

题目大意:

*--代表城市,o--代表空地

给城市安装无线网,一个无线网最多可以覆盖两座城市,问覆盖所有城市最少要用多少无线。

解题报告:

有个想法很不错的,帮助理解最小路径覆盖博客

看了这个题解!!我算是彻底懂了无向图的最小边覆盖的求解过程以及为什么是这么求解,但是博客中有个地方说错了,她说是拆点后变成无向图了,,但是其实是原来就是个无向图(也就是说原博客说拆点后变成双向图了更合适),拆点后变成了两个完全一样的无向图,所以可以最后结果直接除以2,(其实是建图的(二分图的所有顶点-最大匹配)/2  。化简一步才变成了:    复制一遍图之前的顶点(也就是原始图的顶点)- (最大匹配/2))题解如下:神奇啊二分图https://blog.csdn.net/mmy1996/article/details/52289564

但是最小路径覆盖的n都按照拆点之前的算。。。。

无向二分图的最小边覆盖 = 顶点数 – 最大二分匹配数/2

顶点数:就是用于构造无向二分图的城市数,即*的数量

最大二分匹配书之所以要除以2,是因为无向图匹配是双向的,因此除以2得到原图的真正的匹配数

AC代码:

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;

const int MAX = 505;
int n,m,tot;
bool line[MAX][MAX],used[MAX];
int nxt[MAX],vis[MAX][MAX];
char maze[MAX][MAX];
bool find(int x) {
	for(int i = 1; i<=tot; i++) {
		if(line[x][i] && used[i] == 0) {
			used[i] = 1;
			if(nxt[i] == -1 || find(nxt[i])) {
				nxt[i] = x;
				return 1;
			}
		}
	}
	return 0 ;
}
int match() {
	int sum = 0;
	memset(nxt,-1,sizeof nxt);
	for(int i = 1; i<=tot; i++) {
		memset(used,0,sizeof used);
		if(find(i)) sum++;
	}
	return sum;
}
int main()
{
	int t;
	cin>>t;
	while(t--) {
		tot=0;
		scanf("%d%d",&n,&m);//n行m列
		memset(line,0,sizeof line);
		memset(vis,0,sizeof vis);
		for(int i = 1; i<=n; i++) scanf("%s",maze[i]+1);
		for(int i = 1; i<=n; i++) {
			for(int j = 1; j<=m; j++) {
				if(maze[i][j] == '*') vis[i][j] = ++tot;
			}
		} 
		for(int i = 1; i<=n; i++) {
			for(int j = 1; j<=m; j++) {
				if(maze[i][j] == '*') {
					if(i-1 >= 1 && maze[i-1][j] == '*') line[vis[i][j]][vis[i-1][j]]=1;
					if(i+1 <= n && maze[i+1][j] == '*') line[vis[i][j]][vis[i+1][j]]=1;
					if(j-1 >= 1 && maze[i][j-1] == '*') line[vis[i][j]][vis[i][j-1]]=1;
					if(j+1 <= m && maze[i][j+1] == '*') line[vis[i][j]][vis[i][j+1]]=1;
				}
			}
		}
		printf("%d\n",tot - (match()/2));
	}
	
	return 0 ;
 }