#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. Django-权限信息中间件操作

    # 在当前app下新建一个middleware的文件夹,然后就可以尽情的写中间件了,只能是这个名字,切记~@!import re from django.shortcuts import redire ...

  2. iOS设计模式 - (3)简单工厂模式

    iOS设计模式 - (3)简单工厂模式           by Colin丶 转载请注明出处:              http://blog.csdn.net/hitwhylz/article/ ...

  3. VS2008转VS2013时遇到的问题

    最近我们要把DPM进行行人检测嵌入到我们的项目里,需要一个高级版本的VS,于是我们要把2008转换成2013,至于为什么没有换成最高级的版本,可能担心会遇到有更多的麻烦吧,毕竟我们的DPM源码是在20 ...

  4. CentOS笔记-磁盘管理

    Linux磁盘管理常用三个命令为df.du和fdisk. df:列出文件系统的整体磁盘使用量 du:检查磁盘空间使用量 fdisk:用于磁盘分区 df [-ahikHTm] [目录或文件名] -a : ...

  5. GitExtensions 官方手册(英文)

    在线版本(最新版):https://git-extensions-documentation.readthedocs.io/en/latest/ PDF版本(版本号 2.48):http://pan. ...

  6. 解析SQL中的包含的列和表

    using System; using System.IO; using System.Collections.Generic; namespace SQLProcess { class Progra ...

  7. 百度自然语言处理api用法

    def words url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?access_token=1111111" param ...

  8. 蓝牙BlueTooth技术学习理解

    1.BLUETOOTH基本了解 BLUETOOTH出自丹麦 Bluetooth SIG 蓝牙技术联盟,非盈利组织.主要任务是发布蓝牙规格.管理资格认证程序.保护蓝牙商标及宣传蓝牙无线技术. 重要网站 ...

  9. SQL Server2005+、MySQL、Oracle 数据库字典生成工具

    之前找的数据库字典生成工具基本上都依赖于 Office Com 组件,在不安装 Office的情况下无法使用.怒,于是自己用C# 写了一个.     特征如下:         一.支持的数据库 MS ...

  10. uses-permission和permission详解

    1.<uses-permission>: 官方描述: If an application needs access to a feature protected by a permissi ...