Binary graph matching (Hungarian algorithm) UVA 670 the dog task

Source: Internet
Author: User

Topic Portal

1 /*2 Test instructions: Bob walks in the specified order, his dog can go to a spot before he reaches the next point and return in time, asking the dog how many sights to walk3 Hungarian algorithm: According to the dog can smooth to a scenic spot divided into two sets, set a template4 */5#include <cstdio>6#include <algorithm>7#include <cstring>8#include <cmath>9#include <vector>Ten using namespacestd; One  A Const intMAXN = 1e2 +Ten; - Const intINF =0x3f3f3f3f; - structP the { -     intx, y; -     DoubleNXT; - }BOB[MAXN], DOG[MAXN]; + DoubleD[MAXN][MAXN]; - BOOLVIS[MAXN]; + intLK[MAXN]; A intLK2[MAXN]; atvector<int>G[MAXN]; -  - DoubleGet_dis (intX1,intY1,intX2,inty2) - { -     returnsqrt ((1.0) * ((X1-X2) * (X1-X2) + (y1-y2) * (y1-( y2) )); - } in  - BOOLDFS (intu) to { +      for(intI=0; I<g[u].size (); ++i) -     { the         intv =G[u][i]; *         if(!Vis[v]) $         {Panax NotoginsengVIS[V] =true; -             if(Lk[v] = =-1||DFS (Lk[v])) the             { +LK[V] = u; Lk2[u] = v;return true; A             } the         } +     } -  $     return false; $ } -  - voidHungaryintN) the { -     intres =0; memset (LK,-1,sizeof(LK)); memset (LK2,-1,sizeof(LK2));Wuyi      for(intI=1; i<n; ++i) the     { -memset (Vis,false,sizeof(Vis)); Wu         if(DFS (i)) res++; -     } About  $printf ("%d\n", n +res); -      for(intI=1; i<n; ++i) -     { -printf ("%d%d", bob[i].x, bob[i].y); A         if(Lk2[i]! =-1) printf ("%d%d", dog[lk2[i]].x, dog[lk2[i]].y); +     } theprintf ("%d%d\n", bob[n].x, bob[n].y); - } $  the intMainvoid)//UVA 670 the dog task the { the //freopen ("uva_670.in", "R", stdin); the  -     intT scanf ("%d", &t); in      while(t--) the     { the         intN, M; scanf ("%d%d", &n, &m); About          for(intI=1; i<=n; ++i) the         { thescanf ("%d%d", &bob[i].x, &bob[i].y); G[i].clear (); the         } +          for(intI=1; i<=m; ++i) -         { thescanf ("%d%d", &dog[i].x, &dog[i].y);Bayi         } the  the          for(intI=1; i<=n; ++i) -         { -              for(intj=1; j<=m; ++j) the             { theD[I][J] =Get_dis (bob[i].x, Bob[i].y, dog[j].x, dog[j].y); the             } the         } -  the          for(intI=1; i<n; ++i) the         { theBOB[I].NXT = Get_dis (bob[i].x, BOB[I].Y, bob[i+1].x, bob[i+1].y);94         } the  the          for(intI=1; i<n; ++i) the         {98              for(intj=1; j<=m; ++j) About             { -                 if(D[i][j] + d[i+1][J] <=2*bob[i].nxt) G[i].push_back (j);101             }102         }103 104 Hungary (n); the         if(t) puts ("");106     }107 108     return 0;109}

Binary graph matching (Hungarian algorithm) UVA 670 the dog task

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.