#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. 这样看ACM是不是更好?

    如果搞ACM只是为了拿奖,为了保研,这样太功利,整个过程都会变得没意思.我说过我同时看中过程和结果. 其实ACM解题也不是那么没意思,每次AC都有一种非常棒的成就感,每个题目就像是一个解谜游戏,完成了 ...

  2. Android的Message Pool是个什么鬼,Message Pool会否引起OOM——源代码角度分析

    引言 Android中,我们在线程之间通信传递通常採用Android的消息机制,而这机制传递的正是Message. 通常.我们使用Message.obtain()和Handler.obtainMess ...

  3. VB.net版机房收费系统——结账功能实现(调错与优化)

    调错部分 上一篇博客<VB.net版机房收费系统--结账功能实现(代码部分>说的是结账功能的实现,亮出了代码.是在为这篇博客做铺垫.尽管结账功能代码是借鉴的巨人的博客.可是自己比着葫芦画瓢 ...

  4. iOS清理WebView的缓存

    NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; ...

  5. sim的准确识别技术

    几个月钱,我换了一个手机,本着工科男动手能力强的原则,自己用✂️把sim卡剪成了一个小卡,然后成功的可以使用了. 然而就在昨天,我将卡拿出之后,再放回去,却无法识别我的sim卡了. 我上网查了方法,怀 ...

  6. C# List Find方法

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

  7. 一步一步学Silverlight 2系列(9):使用控件模板

    述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...

  8. [Selenium] The commonly used validation method

    Assert.assertTrue(tmpEl.getAttribute("class").contains("selected"),"The fol ...

  9. MyBatis学习 之 三、SQL语句映射文件(2)增删改查、参数、缓存

    2.2 select 一个select 元素非常简单.例如: <!-- 查询学生,根据id --> <select id="getStudent" paramet ...

  10. Watir: 如何处理简单的网页弹出警告框?

    以下是一个很经典的把Watir与AutoIt连接在一起的实例.如果我们对AutoIT了解的更多,处理类似的问题会更加简单.以下实例会判断页面上是否有某“删除”链接,一旦有该链接,就点击,然后点击弹出的 ...