Hdu 41,692 min Matching maximum standalone set * * *

Source: Internet
Author: User

Test instructions: There are horizontal n cards, vertical m cards, cards in the same direction will not intersect. Horizontal and vertical may intersect, asking for a minimum number of cards to be kicked out so that the remaining cards do not intersect.

Binary matching minimum point overwrite = maximum match.

Link: Point Me

Sit punctuation as a matching endpoint

1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const intinf=0x3f3f3f3f; One Const Doubleeps=1e-5; AtypedefLong Longll; - #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); the intN,m,tt; - /* - * Hungarian algorithm adjacency table Form - * Initialize with init () before use, assign value to UN + * Add edge using function Addedge (u,v) - * + */ A Const intMAXN =2505;//maximum number of points at Const intMAXM =50010;//maximum number of edges - structEdge - { -     intTo,next; - }EDGE[MAXM]; - intHead[maxn],tot; in voidInit () - { totot =0; +memset (head,-1,sizeof(head)); - } the voidAddedge (intUintv) * { $Edge[tot].to = v; Edge[tot].next =Head[u];Panax NotoginsengHead[u] = tot++; - } the intLINKER[MAXN]; + BOOLUSED[MAXN]; A intUN; the BOOLDfsintu) + { -      for(inti = Head[u]; I! =-1; i =edge[i].next) $     { $         intv =edge[i].to; -         if(!Used[v]) -         { theUSED[V] =true; -             if(Linker[v] = =-1||DFS (Linker[v]))Wuyi             { theLINKER[V] =u; -                 return true; Wu             } -         } About     } $     return false; - } - intHungary () - { A     intres =0; +memset (linker,-1,sizeof(linker)); the      for(intU =0; U < un;u++)//number of points 0~un-1 -     { $memset (Used,false,sizeof(used)); the         if(Dfs (U)) res++; the     } the     returnRes; the } -pair<int,int>P1[MAXN]; inpair<int,int>P2[MAXN]; the intMain () the { About     inti,j,k; the #ifndef Online_judge theFreopen ("1.in","R", stdin); the     #endif +      while(SCANF ("%d%d", &n,&m)! =EOF) -     { the         if(n==0&&m==0) Break;Bayi init (); the         intx, y; the          for(i=0; i<n;i++) -         { -scanf"%d%d",&x,&y); thep1[i]=Make_pair (x, y); the         } the          for(i=0; i<m;i++) the         { -scanf"%d%d",&x,&y); thep2[i]=Make_pair (x, y); the         } theun=N;94          for(i=0; i<n;i++) the         { the              for(j=0; j<m;j++) the             {98                 intx1=P1[i].first; About                 inty1=P1[i].second; -                 intX2=P2[j].first;101                 intY2=P2[j].second;102                 if((x1==x2&&y1==y2) | | (x1+1==x2&&y1==y2) | | (x1==x2&&y1==y2+1)|| (x1+1==x2&&y1==y2+1))103                 {104 Addedge (i,j); the                 }106             }107         }108printf"%d\n", n+m-Hungary ());109     } the}

Hdu 41,692 min Matching maximum standalone set * * *

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.