Test instructions: There are some points in a matrix that cover these points with a small matrix of 1*2, and the minimum number of small matrices required;
Reference: http://blog.csdn.net/lyy289065406/article/details/6647040
Idea: Non-graph minimum edge coverage = number of vertices-maximum number of matches/2;
Each of the points to be matched is represented by a unique number, which is equivalent to discretization and easy to build;
Each point to be matched is built with an adjacent point;
Since the map is the matrix as a binary graph, a point is split into two points, so the maximum number of matches to be divided by two;
Because unmatched points also need to be overwritten, the result is the number of vertices-the maximum number of matches/2;
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;intn,m,t,cnt;Chartemp;intmm[550][550];intvis[5050],link[5005];intmark[505][550];intdir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};intDfsintx) { for(intI=1; i<=cnt;i++){ if(!vis[i]&&Mark[x][i]) {Vis[i]=1; if(link[i]==-1||DFS (Link[i])) {Link[i]=x; return 1; } } } return 0;}intHungary () {intsum=0; memset (Link,-1,sizeof(link)); for(intI=1; i<=cnt;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) sum++; } returnsum;}intMain () {intans,i,j,k; while(SCANF ("%d", &t)! =EOF) { while(t--) {CNT=0; memset (MM,0,sizeof(mm)); memset (Mark,0,sizeof(Mark)); scanf ("%d%d",&n,&m); for(i=0; i<n;i++) { for(j=0; j<m;j++) {scanf ("%c",&temp); if(temp=='*') {Mm[i][j]=++cnt;//each point is represented by a number } } } for(i=0; i<n;i++) { for(j=0; j<m;j++) { if(Mm[i][j]) for(k=0;k<4; k++){ intxx=i+dir[k][0]; intyy=j+dir[k][1]; if(mm[xx][yy]&&xx>=0&&yy>=0&&XX<N&&YY<M) {//adjacent build edgesmark[mm[xx][yy]][mm[i][j]]=1; MARK[MM[I][J]][MM[XX][YY]]=1; } }}} printf ("%d\n", Cnt-hungary ()/2); } } return 0;}
POJ antenna Placement (minimum side coverage)