Title Link: http://poj.org/problem?id=2560
Just want to say "All is a routine", the key building map.
#include <stdio.h>#include<string.h>#include<math.h>#defineINF 0x3f3f3f3fintN;Doublemaps[ -][ -];BOOLvis[ -];Doubledis[ -];structPoint {Doublex; Doubley;} points[ -];DoublePrim () {memset (Vis,false,sizeof(VIS)); for(intI=1; i<=n;i++) Dis[i]=INF; dis[1] =0; DoubleAns =0; for(intI=1; i<=n;i++) { DoubleTMP =INF; intK =0; for(intj=1; j<=n;j++) { if(!vis[j]&&dis[j]<tmp) {tmp=Dis[j]; K=J; }} Vis[k]=true; Ans+=tmp; for(intI=1; i<=n;i++) { if(!vis[i]&&dis[i]>Maps[k][i]) dis[i]=Maps[k][i]; } } returnans;}intMain () {scanf ("%d",&N); for(intI=1; i<=n;i++) scanf ("%LF%LF",&points[i].x,&points[i].y); for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) { Doublex = points[i].x-points[j].x; Doubley = points[i].y-points[j].y; MAPS[I][J]= sqrt (x*x+y*y); }} printf ("%.2lf\n", Prim ()); return 0;}
Poj (2560), minimum spanning tree, Prim