HDU 5093 Battle ships

Source: Internet
Author: User

Two-part graph matching

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <cmath>5 #defineMAXN 606 #defineMaxd 15007 using namespacestd;8 intV[maxd][maxd],vist[maxd],math[maxd];9 Ten intCOL[MAXN][MAXN],ROW[MAXN][MAXN]; One intk1,k2,n,m; A CharSTR[MAXN][MAXN]; - voidCreat_row () - { thek1=1; -      for(intI=0; i<m;i++) -     { -         intflag=0; +          for(intj=0; j<n;j++) -         { +             if(str[i][j]=='*') A             { atrow[i][j]=K1; -flag=1; -             } -             if(str[i][j]=='#') -             { -k1++; inflag=0; -             } to         } +         if(flag) -k1++; the     } * } $ voidCreat_col ()Panax Notoginseng { -K2=1; the      for(intj=0; j<n;j++) +     { A         intflag=0; the          for(intI=0; i<m;i++) +         { -             if(str[i][j]=='*') $             { $col[i][j]=K2; -flag=1; -             } the             if(str[i][j]=='#') -             {Wuyik2++; theflag=0; -             } Wu         } -         if(flag) Aboutk2++; $     } - } - intDfsintx) - { A      for(intI=1; i<k2;i++) +     { the         if(!vist[i]&&V[x][i]) -         { $vist[i]=1; the             if(math[i]==-1||DFS (Math[i])) the             { themath[i]=x; the                 return true; -             } in  the         } the     } About     return false; the } the voidKM () the { +     intcn1=0; -      for(intI=1; i<k1;i++) the     {Bayimemset (Vist,0,sizeof(vist)); the         if(Dfs (i)) ans++; the     } -printf"%d\n", ans); - } the intMain () the { the     intT; thescanf"%d",&t); -      while(t--) the     { thescanf"%d%d",&m,&n); the          for(intI=0; i<m; i++)94scanf"%s",&str[i]); the Creat_row (); the Creat_col (); the         //printf ("%d%d==\n", K1,K2);98memset (V,0,sizeof(v)); Aboutmemset (math,-1,sizeof(math)); -          for(intI=0; i<m; i++)101         {102              for(intj=0; j<n; J + +)103             {104                 if(str[i][j]=='*') thev[row[i][j]][col[i][j]]=1;106             }107 108         }109 KM (); the     }111     return 0; the}

HDU 5093 Battle ships

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.