# 畅通工程再续

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description

Input

Output

Sample Input
`2210 1020 2031 12 21000 1000`

Sample Output
`1414.2oh!`

`#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int INF=0x3f3f3f3f;int n,u,cnt,vis[105],dis[105],g[105][105];//dis[i]表示点i到最小生成树的距离double ans;struct Point {    int x,y;}p[105];void Prim() {    int i;    memset(vis,false,sizeof(vis));    memset(dis,0x3f,sizeof(dis));    ans=cnt=dis[1]=0;    while(true) {        u=0;        for(i=1;i<=n;++i)            if(!vis[i]&&dis[i]<dis[u])                u=i;        if(u==0)            return ;        vis[u]=true;        ++cnt;        ans+=sqrt(double(dis[u]))*100;        for(i=1;i<=n;++i)            dis[i]=min(dis[i],g[u][i]);    }}int main() {    int i,j,T,t,dx,dy;    scanf("%d",&T);    while(T--) {        memset(g,0x3f,sizeof(g));        scanf("%d",&n);        for(i=1;i<=n;++i) {            scanf("%d%d",&p[i].x,&p[i].y);            for(j=1;j<i;++j) {                dx=p[i].x-p[j].x,dy=p[i].y-p[j].y;                t=dx*dx+dy*dy;                if(100<=t&&t<=1000000)                    g[i][j]=g[j][i]=t;//为了避免产生精度问题，权值为距离的平方            }        }        Prim();        if(cnt==n)            printf("%.1lf\n",ans);        else            printf("oh!\n");    }    return 0;}`

0 0