全程double精度就能过了 间接0距离不用管 prim自动连起来的

G++交的话只能用%f输出 C++的话加不加l都可以 (这么说以后用%f肯定不会错咯)

不过我不懂为什么他们的空间时间差了好多倍...

#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3F3F3F3F
using namespace std; struct Node{double x, y, z, r;}node[]; typedef pair<double, int> pdi;
struct cmp{
bool operator () (const pdi a, const pdi b){
return a.first > b.first;
}
}; double val[][]; double nodeDist(Node a, Node b){
return max(0.0, sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)
+ (a.z-b.z)*(a.z-b.z)) - a.r - b.r);
} double prim(int n, int s)
{
double ans = , dist[];
bool vis[];
memset(vis, false, sizeof vis);
priority_queue<pdi, vector<pdi>, cmp> q; for(int i = ; i <= n; i++){
dist[i] = val[s][i];
q.push(make_pair(dist[i], i));
}
vis[s] = true;
while(!q.empty()){
pdi u = q.top();
q.pop();
if(vis[u.second]) continue;
vis[u.second] = true;
ans += u.first;
for(int i = ; i <= n; i++){
if(!vis[i] && dist[i] > val[u.second][i]){
dist[i] = val[u.second][i];
q.push(make_pair(dist[i], i));
}
}
}
return ans;
} int main()
{
int n;
while(scanf("%d", &n), n){
for(int i = ; i <= n; i++){
scanf("%lf%lf%lf%lf", &node[i].x, &node[i].y, &node[i].z, &node[i].r);
for(int j = ; j <= i; j++){
val[i][j] = val[j][i] = nodeDist(node[i], node[j]);
}
}
printf("%.3f\n", prim(n, ));
}
return ;
}

kuangbin_MST C (POJ 2031)的更多相关文章

  1. POJ 2031 prim

    Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4400 Accepted: 2 ...

  2. Building a Space Station POJ - 2031

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

  3. poj 2031 Building a Space Station(prime )

    这个题要交c++, 因为prime的返回值错了,改了一会 题目:http://poj.org/problem?id=2031 题意:就是给出三维坐标系上的一些球的球心坐标和其半径,搭建通路,使得他们能 ...

  4. POJ - 2031 Building a Space Station(计算几何+最小生成树)

    http://poj.org/problem?id=2031 题意 给出三维坐标系下的n个球体,求把它们联通的最小代价. 分析 最小生成树加上一点计算几何.建图,若两球体原本有接触,则边权为0:否则边 ...

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

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

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

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

  7. POJ - 2031 Building a Space Station 【PRIME】

    题目链接 http://poj.org/problem?id=2031 题意 给出N个球形的 个体 如果 两个个体 相互接触 或者 包含 那么 这两个个体之间就能够互相通达 现在给出若干个这样的个体 ...

  8. 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 ...

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

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

随机推荐

  1. git github 异常

    git :版本控制工具 github:项目托管 git clone failed:git是否安装正确 github commit failed:github 是否账号 / 密码是否正确(密码错误也可以 ...

  2. maven eclipse 安装

    jdk 的 系统变量一定要用  JAVA_HOME maven 的系统变量也一定要用  M2_HOME 配置在path 中 一定要用  %JAVA_HOME%\bin;  和 %M2_HOME%\bi ...

  3. bootstrap笔记-栅格布局

    1.   .clearfix 这个类可以在栅格布局中起到一个不占空间的clear的作用,如下:可以尝试带.clearfix和不带它的区别 <div class="container-f ...

  4. css样式设计

    1.行内元素(图片.文本)水平居中 通过给父元素设置 text-align:center html代码: <body> <div class="txtCenter" ...

  5. win7任务栏只显示日期不显示年月日

    某一天突然发现笔记本任务栏上的时间显示只剩下了时间,没有了年月日 于是百度 搜到的结果大多是如何设置显示的格式  yyyy-MM-dd 继续搜 终于搜到了正确答案 结果令我瞠目结舌  着实无奈 是因为 ...

  6. AC自动机最好讲解

    http://www.cs.uku.fi/~kilpelai/BSA05/lectures/slides04.pdf

  7. 贪心算法 hdu 1009

    1.因为要排序只派j[i]/f[i],不能知道f[i]和j[i]各自排序后的顺序,因此要用到结构体 2.用sort(ware,ware+n,cmp) cmp 为俩个数组的元素比较大小的布尔值 #inc ...

  8. Objective-C的面向对象中,类有真正的私有方法和私有属性么?

    在Java/C#等面向对象语言中,方法的访问权限可以通过public/private/protected来控制其访问权限.而在OC中,方法却并没有访问修饰符.那么,我们有没有办法使其方法变为私有? 1 ...

  9. 一个 11 行 Python 代码实现的神经网络

    一个 11 行 Python 代码实现的神经网络 2015/12/02 · 实践项目 · 15 评论· 神经网络 分享到:18 本文由 伯乐在线 - 耶鲁怕冷 翻译,Namco 校稿.未经许可,禁止转 ...

  10. lamp环境搭配(centos6.4)

    (一)如果你的服务器没有链接网络可以先挂载本地光盘.设置yum源. 挂载光盘: [root@delphi ~]# mkdir /mnt/cdrom #新建挂载点 [root@delphi ~]# mo ...