Topic Portal
1 /*2 Test Instructions: * The point occupy can incidentally occupy four directions of a *, ask at least how many3 Hungarian algorithm: According to the parity of the coordinates of the * divided into two sets, then in addition to the matching one side is incidentally occupied outside, the other will occupy4 */5#include <cstdio>6#include <algorithm>7#include <cstring>8#include <vector>9 using namespacestd;Ten One Const intMAXN = 4e2 +Ten; A Const intINF =0x3f3f3f3f; - Chars[ -][ One]; - intha[ -][ One]; the BOOLVIS[MAXN]; - intLK[MAXN]; -vector<int>G[MAXN]; - intdx[4] = {-1,1,0,0}; + intdy[4] = {0,0, -1,1}; - intun, vn; + A BOOLDFS (intu) at { - for(intI=0; I<g[u].size (); ++i) - { - intv =G[u][i]; - if(!Vis[v]) - { inVIS[V] =true; - if(Lk[v] = =-1||DFS (Lk[v])) to { +LK[V] = u;return true; - } the } * } $ Panax Notoginseng return false; - } the + intHungaryvoid) A { the intres =0; memset (LK,-1,sizeof(LK)); + for(intI=1; i<=un; ++i) - { $memset (Vis,false,sizeof(Vis)); $ if(DFS (i)) res++; - } - the returnRes; - }Wuyi the intMainvoid)//POJ 3020 Antenna Placement - { Wu //freopen ("poj_3020.in", "R", stdin); - About intT scanf ("%d", &t); $ while(t--) - { - intH, W; scanf ("%d%d", &h, &W); - for(intI=1; i<=h; ++i) A { +scanf ("%s", S[i] +1); the } - $Un = VN =0; the for(intI=1; i<=h; ++i) the { the for(intj=1; j<=w; ++j) the { - if(S[i][j] = ='*') in { the if((I+J) &1) Ha[i][j] = + +un; the ElseHA[I][J] = + +vn; About } the } the } the + for(intI=1; i<=un; ++i) g[i].clear (); - the for(intI=1; i<=h; ++i)Bayi { the for(intj=1; j<=w; ++j) the { - if(S[i][j] = ='*'&& (I+J) &1) - { the for(intk=0; k<4; ++k) the { the inttx = i + dx[k];intTy = j +Dy[k]; the if(TX >=1&& TX <= h && Ty >=1&& Ty <= w && s[tx][ty] = ='*') - G[ha[i][j]].push_back (Ha[tx][ty]); the } the } the }94 } the theprintf ("%d\n", UN + VN-Hungary ()); the }98 About return 0; -}
Binary graph matching (Hungarian algorithm) POJ 3020 Antenna Placement