全程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. iOS - C 应用

    前言 1)操作符两端必须加空格,(每行第一个赋值语句对齐). 2)变量名必须是英文(不能是拼音):英文.数字.下划线和美元符号. 3)等于号 == 反过来写(0 == i%4)防止少些赋值号的错误. ...

  2. nodejs 访问mysql

    安装 $ npm install mysql 简介 这个一个mysql的nodejs版本的驱动,是用JavaScript来编写的.不需要编译 这儿有个例子来示范如何使用: var mysql = re ...

  3. 【CSU1812】三角形和矩形 【半平面交】

    检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...

  4. centos6.5安装sublime text 2

    今天在看ueillemmx的博客的时候,看到一神级编辑器,随即安装试了试,我了个去,果然好用,自动补全,自动对齐,样样精通啊! 下面是根据ueillemmx的步骤在CentOS上安装Sublime的过 ...

  5. 用hasOwnProperty获取对象自身的属性排除原型链

    今天遇到一个多层级的object. 需要判定每一层级的data下是否有title属性.在下图中展开的data自身其实是没有title的,但由于受到原型链__proto__的影响,在获取parent.d ...

  6. Python学习笔记只列表和元组

    一.成员资格 1.检查某个字符是否在某个字符串中:'a' in 'absent' 2.获取数组的长度.最大.最小值: numbers=[100,54,345] len(numbers) //长度 ma ...

  7. sanBox部署简介

    参考资料:1  http://www.kaaproject.org/getting-started/  此链接告诉我们部署sandbox的两种方法. 2   http://docs.kaaprojec ...

  8. @keyframes

    通过 @keyframes 规则,您能够创建动画. @keyframes movelike{ from{right:1205px;} to{right:0px}} 创建动画的原理是,将一套 CSS 样 ...

  9. CentOS7下安装FTP服务

    1.安装vsftp 1.1.安装vsftp,测试安装的vsftpd的版本是:vsftpd.x86_64 0:3.0.2-11.el7_2 yum -y install vsftpd 1.2.修改配置文 ...

  10. string.Format格式化

    ,)//填充,结果为02,003