This problem is quite like hdu 5093 Battle ships, but that question is required to place the most points, and this problem is required minimum coverage.
An important position has (x, y) two coordinates, and to hold this position is equivalent to a side x to Y edge.
Selecting one (x, y) is equivalent to selecting all sides of the same x or all the same y edges.
When all x or Y is selected, the guard is completed. The equivalent is cut x and Y, so is the minimum cut, for a capacity of 1 models can be used in the Hungarian algorithm.
If you have an obstacle, just consider the separate side of the barrier and take a break.
The array is bigger, don't re.
#include <bits/stdc++.h>using namespacestd;Const intN =5002;Const intMAXN =101;CharG[MAXN][MAXN];intyid[maxn][maxn],y_cnt;intMatch[n];intDfst[n],dfstime;vector<int>G[n];#definePB push_backBOOLDfsintu) { for(inti =0; I < g[u].size (); i++){ intv =G[u][i]; if(Dfst[v]! =dfstime) {Dfst[v]=Dfstime; if(!~match[v] | |DFS (Match[v])) {Match[v]= u;return true; } } } return false;}intMaxmatch () {intRET =0; memset (Match,-1,sizeof(match)); memset (DFST,0,sizeof(DFST)); Dfstime=0; for(inti =0; i < y_cnt; i++) {Dfstime++; if(Dfs (i)) ret++; } returnret;}intMain () {//freopen ("In.txt", "R", stdin); intC scanf"%d",&b); while(c--){ intY, X, P; scanf"%d%d%d",&y,&x,&P); Memset (g,0,sizeof(g)); while(p--) { intR,C;SCANF ("%d%d",&r,&c); G[R][C]='*'; } scanf ("%d",&q); while(p--){ intR,C;SCANF ("%d%d",&r,&c); G[R][C]='#'; } y_cnt=0; for(inti =1; I <= y;i++){ BOOLFlag =false; for(intj =1; J <= X; J + +){ if(G[i][j] = ='*') flag =true, yid[i][j] =y_cnt; Else if(G[i][j] = ='#'&& flag) y_cnt++; } if(flag) y_cnt++; } for(inti =0; i < y_cnt; i++) g[i].clear (); intx_cnt =0; for(intj =1; J <= X; J + +){ BOOLFlag =false; for(inti =1; I <= Y; i++){ if(G[i][j] = ='*') {flag=true; G[YID[I][J]]. PB (X_CNT); }Else if(G[i][j] = ='#'&&flag) {x_cnt++; } } if(flag) x_cnt++; } printf ("%d\n", Maxmatch ()); } return 0;}
UVA 12549Sentry Robots