#include<iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stdio.h>
using namespace std;
#define mem(arr,a) memset(arr,a,sizeof(arr))
#define V 1000+4
#define sc(t) scanf("%d",&t);
#define pow(a) ((a)*(a))
#define INF 2000.0
double cost[V][V];
int vis[V];
double minCost[V];
struct node{
int x, y;
};
node vet[V];
int cnt;
int n;
int t;
void prim(){
double sum = 0;
for (int i = 1; i <= n; i++){
minCost[i] = cost[1][i];
vis[i] = 0;
}
cnt = n;
minCost;
while (cnt--){
int marks = 0; double MIN = INF;
for (int i = 1; i <= n; i++){
if (!vis[i] && MIN > minCost[i]){
MIN = minCost[i];
marks = i;
}
}
if (marks == 0)break;
vis[marks] = 1;
sum += minCost[marks];
for (int i = 1; i <= n; i++){
if (minCost[i] > cost[marks][i])minCost[i] = cost[marks][i];
}
}
sum *= 100.0;
if (cnt==-1)
printf("%.1f\n", sum);
else printf("oh!\n");
}
int main(){
while (~scanf("%d", &t))
{
while (t--){
scanf("%d", &n);
for (int i = 1; i <= n; i++){
scanf("%d%d", &vet[i].x, &vet[i].y);
}
for (int i = 1; i <= n; i++){
for (int j = 1; j < i; j++){
double sum = sqrt(pow(vet[i].x - vet[j].x) + pow(vet[i].y - vet[j].y));
if (sum >= 10.0 && sum <= 1000.0)cost[i][j] = cost[j][i] = sum;
else cost[i][j] = cost[j][i] = INF;
}
}
prim();
}
}
}
HDU - 1875畅通工程再续
最新推荐文章于 2021-07-28 18:42:26 发布