POJ 3041-asteroids-binary Map matching

Source: Internet
Author: User

Test instructions: Classic binary graph matching problem. A n*n matrix is given, which has a k obstacle. A single star cannon can be clear of a row or a row of obstacles. The minimum number of cannons.

Practice: You can consider the maximum point coverage. The left vertex of the map is a row and the right vertex is a column. If there is an obstacle, connect the edge. At this point the maximum point coverage is the minimum number of cannon, which is the maximum matching of the binary graph. You can use the Hungarian algorithm.

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 = -+Ten; - intun,vn; to intg[2*maxn][2*MAXN],LINKER[MAXN]; + BOOLUSED[MAXN]; -  the BOOLDfsintu) * { $      for(intv=1; v<=vn;v++)Panax Notoginseng     { -         if(g[u][v]&&!)Used[v]) the         { +USED[V] =true; A             if(Linker[v] = =-1||DFS (Linker[v])) the             { +LINKER[V] =u; -                 return true; $             } $         } -     } -     return false; the } - Wuyi intHungary () the { -     intres =0; Wumemset (linker,-1,sizeoflinker); -      for(intu=1; u<=un;u++) About     { $memset (Used,false,sizeof(used)); -         if(Dfs (U)) res++; -     } -     returnRes; A } +  the intn,k,m,t; -  $ intMain () the { the      while(~SCANF ("%d%d",&n,&K)) the     { thememset (G,0,sizeofG); -UN = VN =N; in          for(intI=0; i<k;i++) the         { the             intx, y; Aboutscanf"%d%d",&x,&y); theG[x][y] =1; the         } theprintf"%d\n", Hungary ()); +     }     -}

POJ 3041-asteroids-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.