#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
typedef struct
{
int a,b;
double v;
}node;
typedef struct
{
int a,b;
}P;
const int maxn=;
double ans;
int father[maxn];
node graph[maxn*(maxn-)/];
P p[maxn];
int Find(int x)
{
if(father[x]==x)
return x;
else
{
father[x]=Find(father[x]);
return father[x];
}
}
void Union(int x,int y,double v)
{
if(Find(x)!=Find(y))
{
ans+=v*;
father[Find(x)]=Find(y);
}
return;
}
bool cmp(node x,node y)
{
if(x.v<y.v)
return true;
else
return false;
}
int main()
{
double V;
int n;
scanf("%d",&n);
while(n--)
{
ans=;
for(int i=;i<maxn;i++)
father[i]=i;
int m,k;
k=;
scanf("%d",&m);
for(int i=;i<m;i++)
{
scanf("%d%d",&p[i].a,&p[i].b);
}
for(int i=;i<m-;i++)
{
for(int j=i+;j<m;j++)
{
V=sqrt(pow((p[i].a-p[j].a),2.0)+pow((p[i].b-p[j].b),2.0));
if(V<=&&V>=)
{
graph[k].a=i;
graph[k].b=j;
graph[k].v=V;
k++;
}
}
}
sort(graph,graph+k,cmp);
for(int i=;i<k;i++)
Union(graph[i].a,graph[i].b,graph[i].v);
int xx=Find();
int flag;
flag=;
for(int i=;i<m;i++)
{
if(Find(i)!=xx)
{
flag=;
break;
}
}
if(flag==)
printf("oh!\n");
else
printf("%.1lf\n",ans);
}
return ;
}

HDU 1875(最小生成树)的更多相关文章

  1. hdu 1875 最小生成树 prime版

    最小生成树prime版 大致的步骤 首先选取一个到集合最近的点 然后标记起在集合内部 然后更新最短距离 畅通工程再续 Time Limit: 2000/1000 MS (Java/Others)    ...

  2. HDU 1875 最小生成树prim算法

    #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #inc ...

  3. HDU 1875 畅通工程再续 (prim最小生成树)

    B - 畅通工程再续 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  4. HDU 1875 畅通工程再续 (Prim)

    题目链接:HDU 1875 Problem Description 相信大家都听说一个"百岛湖"的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现 ...

  5. hdu 1875 畅通project再续

    链接:hdu 1875 输入n个岛的坐标,已知修桥100元/米,若能n个岛连通.输出最小费用,否则输出"oh!" 限制条件:2个小岛之间的距离不能小于10米,也不能大于1000米 ...

  6. HDU 1233(最小生成树)

    HDU 1233(最小生成树 模板) #include <iostream> #include <algorithm> #include <cstdio> usin ...

  7. hdu 1875 畅通工程再续(prim方法求得最小生成树)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1875 /************************************************* ...

  8. (最小生成树) 畅通工程再续 -- HDU --1875

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1875 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 1875 畅通工程再续 (最小生成树)

    畅通工程再续 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/M Description 相信大家都听说一个"百岛湖&q ...

随机推荐

  1. PAT 天梯赛 L2-013. 红色警报 【BFS】

    题目链接 https://www.patest.cn/contests/gplt/L2-013 思路 可以通过图的连通块个数来判断 假如 一座城市的失去 改变了其他城市之间的连通性 那么 这座城市本来 ...

  2. 锁定xcode api 文档

    1, 打开终端2, 前往Xcode.app, 命令: cd /Applications/Xcode.app 3, 把头文件修改为只读, 命令: sudo chown -hR root:wheel Co ...

  3. SpringSecurityLDap

    ldap,用于用户登录的权限管理, 可参考:http://www.cnblogs.com/icuit/archive/2010/06/10/1755575.html

  4. 驱动框架入门——以LED为例[【转】

    本文转载自;http://blog.csdn.net/oqqHuTu12345678/article/details/72783903 以下内容源于朱有鹏<物联网大讲堂>课程的学习,如有侵 ...

  5. tableView滑动时cell消失

    最近做的工程中,出现个奇怪的问题吗,就是上下滑动tableView的时候,cell还未出屏幕就消失了,找了很久找到了原因,是因为界面中需要的cell有很多种,而有的cell的高度是一开始算出来或是固定 ...

  6. ansible操作模块相关

    1. 查看模块可用参数命令 ansible-doc -s module_name

  7. php函数的参数引用变量

    在php.ini中将allow_call_time_pass_reference的值改为'on'.

  8. CodeForces813E:Army Creation (主席树---上一题的加强版)

    As you might remember from our previous rounds, Vova really likes computer games. Now he is playing ...

  9. VS2008中使用JSONCPP方法小结

    Introduction JSON (JavaScript Object Notation) is a lightweight data-interchange format. It can repr ...

  10. 微信小程序WXML提供了import和include引用方式

    引入的文件需要放在pages文件下: 例如: 在pages文件下新建template文件夹,新建tem1.wxml模板文件 在其他页面中就可以引入tem1.wxml文件../template/tem1 ...