HDU 3360 Minimum Point coverage

Source: Internet
Author: User

Test instructions: Give you a picture, there are two elements of treasure and security. Each treasure needs to be placed at the same time in some locations around the security (if those locations have treasures, you can replace the treasure to security) ask you at least need to place more security, you can make all the treasures meet the requirements.

Test instructions's a little hard to understand.

Link: Point Me

Direct construction of the non-directed graph, less judgment of the parity, and finally a 2 can be

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 Const intMAXN =5010;//maximum number of points - Const intMAXM =50010;//maximum number of edges - intA[MAXN][MAXN]; - intB[MAXN][MAXN]; + intN,m,tt; - /* + * Hungarian algorithm adjacency table Form A * Initialize with init () before use, assign value to UN at * Add edge using function Addedge (u,v) - * - */ - structEdge - { -     intTo,next; in }EDGE[MAXM]; - intHead[maxn],tot; to voidInit () + { -tot =0; thememset (head,-1,sizeof(head)); * } $ voidAddedge (intUintv)Panax Notoginseng { -Edge[tot].to = v; Edge[tot].next =Head[u]; theHead[u] = tot++; + } A intLINKER[MAXN]; the BOOLUSED[MAXN]; + intUN; - BOOLDfsintu) $ { $      for(inti = Head[u]; I! =-1; i =edge[i].next) -     { -         intv =edge[i].to; the         if(!Used[v]) -         {WuyiUSED[V] =true; the             if(Linker[v] = =-1||DFS (Linker[v])) -             { WuLINKER[V] =u; -                 return true; About             } $         } -     } -     return false; - } A intHungary () + { the     intres =0; -memset (linker,-1,sizeof(linker)); $      for(intU =0; U < un;u++)//number of points 0~un-1 the     { thememset (Used,false,sizeof(used)); the         if(Dfs (U)) res++; the     } -     returnRes; in } the intdir[][2] = {{-1,-2},{-2,-1},{-2,1},{-1,2},{1,2}, the{2,1},{2,-1},{1,-2},{-1,0},{0,1},{1,0},{0,-1}}; About intMain () the { the     inti,j,k; the #ifndef Online_judge +Freopen ("1.in","R", stdin); -     #endif the     intCa=1;Bayi      while(SCANF ("%d%d", &n,&m)! =EOF) the     { the         if(n==0&&m==0) Break; -UN =0; -          for(i =0; I < n;i++) the              for(j =0; J < m;j++) the             { theB[I][J] = un++; the             } -          for(i=0; i<n;i++) the         { the              for(j=0; j<m;j++) the             {94scanf"%d",&a[i][j]); the             } the         } the init ();98          for(i=0; i<n;i++) About         { -              for(j=0; j<m;j++)101             {102                 if(a[i][j]!=-1)103                 {104                      for(k=0;k< A; k++) the                     {106                         if(a[i][j]& (1&LT;&LT;K))//this point needs to be placed on guard107                         {108                             intnx=i+dir[k][0];109                             intny=j+dir[k][1]; the                             if(nx>=0&&nx<n&&ny>=0&&ny<m&&a[nx][ny]!=-1)111                             { the Addedge (B[i][j],b[nx][ny]);113 Addedge (B[nx][ny],b[i][j]); the                             } the                         } the                     }117                 }118             }119         } -printf"%d.%d\n", Ca++,hungary ()/2);121     }122}

HDU 3360 Minimum Point coverage

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.