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", &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)