POJ 3020-antenna placement-binary map matching

Source: Internet
Author: User

Test Instructions: There are k points in a n*m matrix, and you must place the antennas over all the observation points. Each radar can only have two observation points on the antenna, and the two points must be adjacent. Calculates the minimum number of antennas.

Practice: Connect all adjacent observation points and build a map. Run it once. The Hungarian algorithm calculates the maximum number of covers, divided by two, the number of antennas. Also add a single point of observation, each of which requires an antenna.

1 /*--------------------------------------------------------------------------------------*/2 //Helica ' s header3 //Second Edition4 //2015.11.75 //6#include <algorithm>7#include <iostream>8#include <cstring>9#include <ctype.h>Ten#include <cstdlib> One#include <cstdio> A#include <vector> -#include <string> -#include <queue> the#include <stack> -#include <cmath> -#include <Set> -#include <map> +  - //Debug function for a n*m array + #defineDebug_map (n,m,g) printf ("\ n"); for (int i=0;i< (N); i++) A{ for(intj=0;j< (M); J + +){ atprintf"%d", G[i][j]);} printf"\ n");}  - //Debug function for int,float,double,etc. - #defineDebug_var (X) cout<< #X "=" <<X<<endl; - /*--------------------------------------------------------------------------------------*/ - using namespacestd; -  in Const intMAXN = -; - intn,m,t; to intg[Ten*maxn][Ten*MAXN],MAP[MAXN][MAXN]; + intdx[4]={1,-1,0,0},dy[4]={0,0,1,-1}; - intlinker[Ten*MAXN]; the BOOLused[Ten*MAXN]; * intun,vn; $ Panax Notoginseng BOOLDfsintu) - { the      for(intv=1; v<=vn;v++) +     { A         if(G[u][v] &&!Used[v]) the         { +USED[V] =true; -             if(Linker[v] = =-1||DFS (Linker[v])) $             { $LINKER[V] =u; -                 return true; -             } the         } -     }Wuyi     return false; the } -  Wu intHungary () - { Aboutmemset (linker,-1,sizeoflinker); $     intres =0; -      for(intu=1; u<=un;u++) -     { -memset (Used,false,sizeofused); A         if(Dfs (U)) res++;  +     }     the     returnRes; - } $  the intMain () the { thescanf"%d",&T); the      while(t--) -     { inscanf"%d%d",&n,&M); the         CharC; theUN =0; About          for(intI=0; i<n;i++) the         { the GetChar (); the              for(intj=0; j<m;j++) +             { -scanf"%c",&c); the                 if(c = ='*') Map[i][j] = + +UN;Bayi                 ElseMAP[I][J] =0; the             } the         } -memset (G,0,sizeofG); -VN =UN; the          for(intI=0; i<n;i++) the         { the              for(intj=0; j<m;j++)if(Map[i][j]) the             { -                 intU =Map[i][j]; the                  for(intp=0;p <4;p + +) the                 { the                     intNX = I+dx[p],ny = j+Dy[p];94                     if(NX >=0&& NX < N && NY >=0&& NY <M) the                     { the                         if(intv =Map[nx][ny]) the                            {98                             //printf ("u:%d v:%d\n", u,v); AboutG[U][V] = G[v][u] =1; -                         }    101                     }102                 }103             }104         } the         106         intAns =Hungary ();107         //printf ("ans:%d un:%d\n", Ans,un);108printf"%d\n", (Un-ans) +ans/2);109     }     the}

POJ 3020-antenna placement-binary map matching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.