Building a Space Station POJ - 2031 三维最小生成树,其实就是板子题
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=1e5;
struct edge{
int a,b;
double w;
}e[N];
double x[N],y[N],z[N],r[N];
int n,tot,p[N];
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
void kruskal()
{
double sum=;
for(int i=;i<tot;i++)
{
int a=find(e[i].a);
int b=find(e[i].b);
double w=e[i].w;
if(a!=b)
{
sum+=w;
p[a]=b;
}
}
printf("%.3f\n",sum);
}
int main()
{
while(cin>>n&&n)
{
for(int i=;i<n;i++)
cin>>x[i]>>y[i]>>z[i]>>r[i];
for(int i=;i<=n;i++)
p[i]=i;
tot=;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{
double t=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(r[i]+r[j]>=t)
e[tot++]={i,j,};
else
e[tot++]={i,j,t-r[i]-r[j]};
}
sort(e,e+tot,cmp);
kruskal(); }
return ;
}
Building a Space Station POJ - 2031 三维最小生成树,其实就是板子题的更多相关文章
- 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 ...
- Building a Space Station POJ - 2031
Building a Space Station POJ - 2031 You are a member of the space station engineering team, and are ...
- (最小生成树) Building a Space Station -- POJ -- 2031
链接: http://poj.org/problem?id=2031 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6011 ...
- C - Building a Space Station - poj 2031
空间站是有一些球状的房间组成的,现在有一些房间但是没有相互连接,你需要设计一些走廊使他们都相通,当然,有些房间可能会有重合(很神奇的样子,重合距离是0),你需要设计出来最短的走廊使所有的点都连接. 分 ...
- POJ-2031 Building a Space Station (球的最小生成树)
http://poj.org/problem?id=2031 Description You are a member of the space station engineering team, a ...
- 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 最小生成树
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6083 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【最小生成树prime】【模板题】
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5699 Accepte ...
随机推荐
- Apache 日志记录相关设置
小编最近在配置Apache 服务器啊 就把遇到的信息给记录下来 Apache 自动生成的日志会给系统带来很大的损耗.关闭日志以后,甚至最高可以提高整体性能近40%(粗略估计) 那么如何关闭日志呢? 可 ...
- 使用helm安装jenkin和gitlab
一.使用服务介绍 存储: 阿里云NAS k8s网络插件: calico k8s版本: 1.15.2 二.helm安装 https://www.cnblogs.com/zhangb8042/p/1020 ...
- js能力测评——查找元素的位置
查找元素的位置 题目描述: 找出元素 item 在给定数组 arr 中的位置 输出描述: 如果数组中存在 item,则返回元素在数组中的位置,否则返回 -1 示例1 输入 [ 1, 2, 3, 4 ] ...
- codewars--js--create phone number
Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of th ...
- webapi+Quartz.NET解决若干定时程序同时运行的问题
项目现状: 有若干定时程序需要自启动运行,为了简便程序部署等问题,采取这种办法把定时程序集中管理到webapi中跟随api发布 代码架构介绍: 新建一个类库,类库引用Quartz(Quartz.2.3 ...
- openlayers6结合geoserver利用WFS服务实现图层新增功能(附源码下载)
内容概览 1.openlayers6结合geoserver利用WFS服务实现图层新增功能2.源代码demo下载 效果图如下: 本篇主要是openlayers6通过调用geoserver发布的地图服务W ...
- Android Gradle报错 (Error:No such property: GradleVersion for class: JetGradlePlugin) 的原因与解决
Error:No such property: GradleVersion for class: JetGradlePlugin 错误原因:IDE 版本(GradlePlugin)和 Gradle 版 ...
- Windows server 2012 出现大量无名已断开连接用户清楚办法
打开cmd命令窗口,执行 taskkill /f /im winlogon.exe /t
- 在本地搭建git服务器
GitHub就是一个免费托管开源代码的远程仓库.但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用. 搭建Gi ...
- JSP开发机票预定系统 源码
开发环境: Windows操作系统开发工具:MyEclipse+Jdk+Tomcat6+Mysql数据库 运行效果图 源码及原文链接:https://javadao.xyz/forum.php?mod ...