HDU 4463 One side must be added (2012 Hangzhou regional Game k)

Source: Internet
Author: User

The Nike store and the Apple store must be connected.


Sample Input
4
2 3
0 0
1 0
0-1
1-1
0

Sample Output
3.41

1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <cmath>6# define LLLong Long7 using namespacestd;8 9 Const intinf=0x3f3f3f3f;Ten Const intmaxn= the; One BOOLVIS[MAXN]; A DoubleLOWC[MAXN]; - intN; - DoubleCOST[MAXN][MAXN]; the  - structPoin - { -     intx; +     inty; - }P[MAXN]; +  A DoublePrim ()//Dot is 0~n-1 at { -     Doubleans=0; -memset (Vis,false,sizeof(Vis)); -vis[0]=true; -      for(intI=1; i<n;i++) lowc[i]=cost[0][i]; -      for(intI=1; i<n;i++) in     { -         DoubleMinc=INF; to         intp=-1; +          for(intj=0; j<n;j++) -             if(!vis[j]&&minc>Lowc[j]) the             { *Minc=Lowc[j]; $p=J;Panax Notoginseng             } -             if(Minc==inf)return-1;//The original is not connected theans+=Minc; +vis[p]=true; A              for(intj=0; j<n;j++) the                 if(!vis[j]&&lowc[j]>Cost[p][j]) +lowc[j]=Cost[p][j]; -     } $     returnans; $ } -  - intMain () the { - Wuyi    //freopen ("In.txt", "R", stdin); the      while(SCANF ("%d", &n)! =EOF) -     { Wu         if(n = =0) -              Break ; About         intI, J; $         intpp, QQ; -scanf"%d%d", &AMP;PP, &QQ); -          for(i =0; I < n; i++) -scanf"%d%d", &p[i].x, &p[i].y); A          for(i =0; I < n; i++) +              for(j = i+1; J < N; J + +) the             { -                 Doublet = sqrt ((Double) (p[i].x-p[j].x) * (p[i].x-p[j].x) + (P[I].Y-P[J].Y) * (P[I].Y-p[j].y)) ; $COST[I][J] =T; theCost[j][i] =T; the             } the         DoubleK = cost[pp-1][qq-1] ; thecost[pp-1][qq-1] =0 ; -cost[qq-1][pp-1] =0 ; inK + =Prim (); theprintf"%.2lf\n", k); the  About  the     } the     return 0 ; the}
View Code

HDU 4463 One side must be added (2012 Hangzhou regional Game k)

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.