#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn = ;
const int L = ;
const int R = ;
int t, n, m, ans;
double total;
struct node
{
int x, y;
int cost;
}pot[maxn];
int fa[maxn];
int px[maxn], py[maxn]; int cal()
{
int i, j, tx, ty, len, pos;
pos = ;
for (i = ; i<n; i++)
{
for (j = i + ; j<n; j++)
{
tx = px[i] - px[j];
ty = py[i] - py[j];
len = tx*tx + ty*ty;
if (len >= L&&len <= R)
{
pot[pos].x = i;
pot[pos].y = j;
pot[pos].cost = len;
pos++;
}
}
}
return pos;
} void init()
{
total = 0.0;
ans = n - ;
for (int i = ; i <= n; i++)
{
fa[i] = i;
}
} bool cmp(node a, node b)
{
return a.cost<b.cost;
} int find(int x)
{
if (x != fa[x])
return fa[x] = find(fa[x]);
return fa[x];
} int join(int x, int y)
{
int flag = ;
if (x != y)
{
ans--;
fa[x] = y;
flag = ;
}
return flag;
} int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
init();
for (int i = ; i<n; i++)
{
scanf("%d %d", &px[i], &py[i]);
}
int len = cal();
if (len<n - )
{
printf("oh!\n");
continue;
}
sort(pot, pot + len, cmp);
for (int i = ; i<len; i++)
{
int fx, fy;
fx = find(pot[i].x);
fy = find(pot[i].y);
if (join(fx, fy) == )
{
total += sqrt(pot[i].cost*1.0);
}
}
if (ans != )
{
printf("oh!\n");
continue;
}
printf("%.1lf\n", total * );
}
return ;
}

hdu1875 畅通工程再续 暴力+基础最小生成树的更多相关文章

  1. HDU1875——畅通工程再续(最小生成树:Kruskal算法)

    畅通工程再续 Description相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当 ...

  2. hdu1875 畅通工程再续 最小生成树并查集解决---kruskal

    http://acm.hdu.edu.cn/showproblem.php?pid=1875 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

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

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

  4. HDU1875 畅通工程再续 (并查集)

    畅通工程再续 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  5. HDU1875 畅通工程再续 2017-04-12 19:52 48人阅读 评论(0) 收藏

    畅通工程再续 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  6. HDU-1875 畅通工程再续(最小生成树+判断是否存在)

    http://acm.hdu.edu.cn/showproblem.php?pid=1875 Problem Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛 ...

  7. hdu1875 畅通工程再续 并查集/最小生成树

    相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全 ...

  8. HDU1875 畅通工程再续【最小生成树】

    题意: 在这些小岛中建设最小花费的桥,但是一座桥的距离必须在10 -- 1000之间. 思路: 用最小生成树解决吧,就那两个算法. 代码: prim #include <iostream> ...

  9. HDU1875 畅通工程再续

    相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全 ...

随机推荐

  1. 为activity添加左右手势识别

    android开发中为activity添加左右手势识别.如右滑关闭当前页面 /* * for左右手势 * 1.复制以下的内容到目标Activity * 2.目标Activity的onCreate()调 ...

  2. sublime 中配置 python 运行

    运行是按快捷键 ”ctrl + B“ Preferences->Browse Packages->Python->Python.sublime-build 编辑这个文件.   修改成 ...

  3. 2016/06/10 日历插件 Datepicker

    显示效果: <!doctype html> <html lang="en"> <head> <meta charset="utf ...

  4. querying rpm database

    Call dbMatch on a transaction set to create a match iterator. As with the C API, a match iterator al ...

  5. 使用 fetch 代替 ajax(在不支持的浏览器上使用 XHR); This kind of functionality was previously achieved using XMLHttpRequest.

    原生 JS Ajax,GET和POST 请求实例代码_javascript技巧_脚本之家 https://www.jb51.net/article/86157.htm 更新时间:2016年06月08日 ...

  6. org.apache.flume.EventDeliveryException: NettyAvroRpcClient { host: hadoop1, port: 41414 }: Failed to send event

    org.apache.flume.EventDeliveryException: NettyAvroRpcClient { host: hadoop1, port: 41414 }: Failed t ...

  7. TiDB 是否支持其他存储引擎?

    https://www.pingcap.com/docs-cn/FAQ/ 1.1.11 TiDB 是否支持其他存储引擎? 是的,除了 TiKV 之外,TiDB 还支持一些流行的单机存储引擎,比如 Go ...

  8. poj 2228 Naptime(DP的后效性处理)

    \(Naptime\) \(solution:\) 这道题不做多讲,它和很多区间DP的套路一致,但是这一道题它不允许断环成链,会超时.但是我们发现如果这只奶牛跨夜休息那么它在不跨夜的二十四个小时里一定 ...

  9. C# List Find方法

    https://blog.csdn.net/knqiufan/article/details/77847143

  10. ruby require

    require一般用来加载其它的类,如:  #Ruby代码  : require 'dbi'   require "rexml/document" 但是上面加载的是标准类库里面的文 ...