空间站是有一些球状的房间组成的,现在有一些房间但是没有相互连接,你需要设计一些走廊使他们都相通,当然,有些房间可能会有重合(很神奇的样子,重合距离是0),你需要设计出来最短的走廊使所有的点都连接。

分析:因为给的都是点的坐标,所以构图的时候会有一些麻烦,不过也仅此而已。。。
*******************************************************************
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
using namespace std; #define maxn 105 struct point{double x, y, z, r;}p[maxn];
struct node
{
    int u, v;
    double len;     friend bool operator < (node a, node b)
    {
        return a.len > b.len;
    }
}; int f[maxn]; double Len(point a, point b)//求两点间的距离
{
    double x = a.x - b.x;
    double y = a.y - b.y;
    double z = a.z - b.z;
    double l = sqrt(x*x+y*y+z*z)-a.r-b.r;     if(l < 0)l = 0;     return l;
}
int Find(int x)
{
    if(f[x] != x)
        f[x] = Find(f[x]);
    return f[x];
} int main()
{
    int N;     while(scanf("%d", &N) != EOF && N)
    {
        int i, j;
        node s;
        priority_queue<node>Q;         for(i=1; i<=N; i++)
        {
            scanf("%lf%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z, &p[i].r);
            f[i] = i;
        }         for(i=1; i<=N; i++)
        for(j=i+1; j<=N; j++)
        {
            s.u = i, s.v = j;
            s.len = Len(p[i], p[j]);
            Q.push(s);
        }         double ans = 0;         while(Q.size())
        {
            s = Q.top();Q.pop();
            int u = Find(s.u), v = Find(s.v);             if(u != v)
            {
                f[u] = v;
                ans += s.len;
            }
        }         printf("%.3f\n", ans);
    }     return 0;
}

C - Building a Space Station - poj 2031的更多相关文章

  1. Building a Space Station POJ - 2031

    Building a Space Station POJ - 2031 You are a member of the space station engineering team, and are ...

  2. (最小生成树) Building a Space Station -- POJ -- 2031

    链接: http://poj.org/problem?id=2031 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6011 ...

  3. Building a Space Station POJ 2031 【最小生成树 prim】

    http://poj.org/problem?id=2031 Description You are a member of the space station engineering team, a ...

  4. Building a Space Station POJ - 2031 三维最小生成树,其实就是板子题

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

  5. POJ 2031 Building a Space Station【经典最小生成树】

    链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  6. poj 2031 Building a Space Station【最小生成树prime】【模板题】

    Building a Space Station Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5699   Accepte ...

  7. POJ 2031 Building a Space Station

    3维空间中的最小生成树....好久没碰关于图的东西了.....              Building a Space Station Time Limit: 1000MS   Memory Li ...

  8. POJ 2031 Building a Space Station (最小生成树)

    Building a Space Station Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5173   Accepte ...

  9. POJ 2031 Building a Space Station (最小生成树)

    Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...

随机推荐

  1. MIME协议

    转:http://blog.csdn.net/flfna/article/details/5048290 MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候 ...

  2. (转)dedecms代码详解 很全面

    dedecms代码研究(1)开篇dedecms 相信大家一定都知道这个cms 系统,功能比较强大,有比较完善的内容发布,还有内容静态化系统,还有就是它有自己独特的标签系统和模板系统.而模板系统也是其他 ...

  3. leetcode修炼之路——383. Ransom Note

    题目是这样的 Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 a ...

  4. 【USACO 3.2.6】香甜的黄油

    [描述] 农夫John发现做出全威斯康辛州最甜的黄油的方法:糖.把糖放在一片牧场上,他知道N(1<=N<=500)只奶牛会过来舔它,这样就能做出能卖好价钱的超甜黄油.当然,他将付出额外的费 ...

  5. 使用C#连接ORACLE数据库

    一.使用OracleClient组件连接Oracle   .Net框架的System.Data.OracleClient.dll组件(ADO.Net组件),为连接和使用Oracle数据库提供了很大的方 ...

  6. jquery validate 配合ligerui使用

    这样当单击登录按钮时右边会弹出一个小框框,同时显示jquery扩展的下面那段代码错误内容,当添加内容正确后小框框消失,lable换成error也行 $("#form1").vali ...

  7. HTML5 QQ登录背景动态图片

    预览效果如图所示: 代码如下: <!DOCTYPE html> <head> <meta http-equiv="Content-Type" cont ...

  8. [javascript]事件冒泡处理

    <!DOCTYPE html> <html> <head> <style type="text/css"> #box1 { widt ...

  9. Django filter中用contains 在mysql中的问题

    用PYTHON ,DJANGO 做站,在通常的情况下,需要用到 orM 的查询方法,比如object.filter(tag__contains='keywords').... 在这种情况下,如果你跟踪 ...

  10. sql server 调优----索引未使用

    SELECT TOP 1000o.name AS 表名, i.name AS 索引名, i.index_id AS 索引id, dm_ius.user_seeks AS 搜索次数, dm_ius.us ...