zoj 1718 poj 2031 Building a Space Station
最小生成树,用了Kruskal算法。POJ上C++能过,G++不能过。。。 算出每两个圆心之间的距离,如果距离小于两半径之和,那么这两个圆心之间的距离直接等于0,否则等于距离-R[i]-R[j]。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn = ;
struct abc{ int start, end; double path; }node[maxn];
bool cmp(const abc&a, const abc&b){ return a.path < b.path; }
double x[maxn], y[maxn], z[maxn], r[maxn];
int father[maxn];
int find(int x)
{
if (x != father[x]) father[x] = find(father[x]);
return father[x];
}
int main()
{
int n, i, j;
while (~scanf("%d", &n))
{
if (n == ) break;
int tot = ;
for (i = ; i <= n; i++) scanf("%lf%lf%lf%lf", &x[i], &y[i], &z[i], &r[i]);
for (i = ; i <= n; i++) father[i] = i;
for (i = ; i <= n; i++)
{
for (j = i + ; j <= n; j++)
{
node[tot].start = i;
node[tot].end = j;
double tt = sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]) + (z[i] - z[j])*(z[i] - z[j]));
if (tt <= r[i] + r[j]) node[tot].path = ;
else node[tot].path = tt - r[i] - r[j];
tot++;
}
}
double ans = ;
sort(node, node + tot, cmp);
for (i = ; i < tot; i++)
{
int xx = find(node[i].start);
int yy = find(node[i].end);
if (xx != yy)
{
father[xx] = yy;
ans = ans + node[i].path;
}
}
printf("%.3lf\n", ans);
}
return ;
}
zoj 1718 poj 2031 Building a Space Station的更多相关文章
- POJ 2031 Building a Space Station【经典最小生成树】
链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2031 Building a Space Station【最小生成树prime】【模板题】
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5699 Accepte ...
- POJ 2031 Building a Space Station
3维空间中的最小生成树....好久没碰关于图的东西了..... Building a Space Station Time Limit: 1000MS Memory Li ...
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5173 Accepte ...
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...
- POJ - 2031 Building a Space Station 三维球点生成树Kruskal
Building a Space Station You are a member of the space station engineering team, and are assigned a ...
- POJ 2031 Building a Space Station (计算几何+最小生成树)
题目: Description You are a member of the space station engineering team, and are assigned a task in t ...
- POJ 2031 Building a Space Station【最小生成树+简单计算几何】
You are a member of the space station engineering team, and are assigned a task in the construction ...
- POJ 2031 Building a Space Station (prim裸题)
Description You are a member of the space station engineering team, and are assigned a task in the c ...
随机推荐
- ADO.NET初学习
①System.Data → DataTable,DataSet,DataRow,DataColumn,DataRelation,Constraint,DataColumnMapping,DataT ...
- 驱动10.nor flash
1 比较nor/nand flash NOR NAND接口: RAM-Like,引脚多 引脚少, ...
- 数据持久层框架iBatis, Hibernate 与 JPA 比较
在本文中我们介绍并比较两种最流行的开源持久框架:iBATIS和Hibernate,我们还会讨论到Java Persistence API(JPA).我们介绍每种解决方案并讨论其所规定的品质,以及在广泛 ...
- 仿qq的侧拉菜单效果
自定义控件 import android.animation.ArgbEvaluator; import android.animation.FloatEvaluator; import androi ...
- D3.js:交互式操作
用户用于交互的工具一般有三种:鼠标.键盘.触屏. 1. 添加交互 对某一元素添加交互操作十分简单,代码如下: //画布大小 var width = 500, height = 500; // 在bod ...
- Linux 编译安装 源代码
编译安装 源代码包的安装一般为下载软件源代码,然后编译安装. 常见的C程序软件的安装步骤是 configure, make, make install三部曲,大致是下面这样操作: 首先得安装gcc.m ...
- JS代码:设为首页 加入收藏
// JavaScript Document // 加入收藏 <a onclick="AddFavorite(window.location,document.title)" ...
- hadoop bug 笔记
1.sqoop从mysql导入数据到hdfs的时候,总是在本地运行,而没有运行在集群上 sqoop 配置文件的问题 在 /usr/lib/sqoop/conf 目录下新增文件 sqoop-env.s ...
- 解决 maven项目问题 An error occurred while filtering resources
解决方法: Maven -> Update Project.
- svn 常用控制台命令解析
参数说明 :serverPath:表示服务器的文件路径 , localPath:表示本地的文件路径 , num 表示数字 , edition1:表示工程已经跟新的版本1 , edition2:表示 ...