The main problem: There are N cities, to establish a radio station in these n cities, each radio station can only cover 2 neighboring cities, ask at least how many wireless power stations need to build
Problem-Solving ideas: English topic good pit, looked at half a day.
This problem is similar to POJ-2446 chessboard.
All cities can be divided into two point sets, then the connection between the radio station to represent the coverage of the relationship.
Because all cities have to be covered, so according to the relationship, find the smallest path coverage can cover all cities
#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace STD;Const intN = the;Const intM = -;intVis[n], link[n],g[m][m], H, W, CNT; vector<int>City[n];CharSTR[M];voidInit () {scanf("%d%d", &h, &w); CNT =0;memset(g,0,sizeof(g)); for(inti =1; I <= H; i++) {scanf('%s ', str); for(intj =0; J < W; J + +)if(Str[j] = =' * ') g[i][j+1] = ++cnt; } for(inti =1; I <= CNT; i++) city[i].clear (); for(inti =1; I <= H; i++) for(intj =1; J <= W; J + +)if(G[i][j]) {ifI1>0&& g[i-1][J]) City[g[i][j]].push_back (g[i-1][J]);if(i +1<= h && g[i+1][J]) City[g[i][j]].push_back (g[i+1][J]);if(J-1>0&& g[i][j-1]) City[g[i][j]].push_back (g[i][j-1]);if(j +1<= W && g[i][j+1]) City[g[i][j]].push_back (g[i][j+1]); }memset(Link,0,sizeof(link));}BOOLDfsintu) { for(inti =0; I < city[u].size (); i++) {intv = city[u][i];if(Vis[v])Continue; VIS[V] =1;if(!link[v] | | DFS (LINK[V)) {Link[v] = u;return true; } }return false;}voidHungary () {intAns =0; for(inti =1; I <= CNT; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", Cnt-ans/2);}intMain () {intTestscanf("%d", &test); while(test--) {init (); Hungary (); }return 0;}
POJ-3020 Antenna Placement Minimum path overlay