博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-2031-Building a Space Station
阅读量:7211 次
发布时间:2019-06-29

本文共 1519 字,大约阅读时间需要 5 分钟。

链接:https://vjudge.net/problem/POJ-2031#author=0

题意:

三维空间,给n个圆心x,y,z,半径r的圆,求最短的连线。

接触不需要连。

思路:

求距离,接触权值为0,不接触为权值长度减半径。

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int MAXM = 10000+10;const int MAXN = 100+10;struct Node{ double _x,_y,_z,_r;}node[MAXN];struct Path{ int _l,_r; double _value; bool operator < (const Path & that)const{ return this->_value < that._value; }}path[MAXM];double Get_Len(Node a,Node b){ return 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));}int Father[MAXN];int Get_F(int x){ return Father[x] = (Father[x] == x) ? x : Get_F(Father[x]);}int main(){ int n; while (cin >> n && n) { for (int i = 1;i<=n;i++) Father[i] = i; for (int i = 1;i<=n;i++) cin >> node[i]._x >> node[i]._y >> node[i]._z >> node[i]._r; int pos = 0; for (int i = 1;i<=n;i++) { for (int j = 1;j<=n;j++) { double len = Get_Len(node[i],node[j]); double r = node[i]._r + node[j]._r; path[++pos]._l = i; path[pos]._r = j; if (len <= r) path[pos]._value = 0; else path[pos]._value = len - r; } } sort(path+1,path+1+pos); double sum = 0; for (int i = 1;i <= pos;i++) { int tl = Get_F(path[i]._l); int tr = Get_F(path[i]._r); if (tl != tr) { Father[tl] = tr; sum += path[i]._value; } } printf("%.3lf\n",sum); } return 0;}

  

转载于:https://www.cnblogs.com/YDDDD/p/10330669.html

你可能感兴趣的文章
WebGIS中解决使用Lucene进行兴趣点搜索排序的两种思路
查看>>
驱动继电器实验
查看>>
技术宅---我的网上抢火车票攻略
查看>>
Android 使用dagger2进行依赖注入(基础篇)
查看>>
如何让帝国CMS7.2搜索模板支持动态标签调用
查看>>
《Oracle DBA工作笔记》第一章
查看>>
全面剖析Redis Cluster原理和应用 (good)
查看>>
PostgreSQL学习手册(常用数据类型)
查看>>
Visual Studio 2013 Xamarin for iOS 环境搭建
查看>>
服务端I/O性能:Node、PHP、Java、Go的对比
查看>>
注解的原理又是怎么一回事
查看>>
【PMP】Head First PMP 学习笔记 第十章 沟通管理
查看>>
阿里巴巴发布AliOS品牌 重投汽车及IoT领域
查看>>
怎么建立网站?
查看>>
剖析 epoll ET/LT 触发方式的性能差异误解(定性分析)
查看>>
实践 Redux,第 1 部分: Redux-ORM 基础
查看>>
英特尔携手AT&T和爱立信进行DIRECTV NOW流媒体直播服务的5G试验
查看>>
微服务,我们如何与你相处
查看>>
“Redirect to SMB”漏洞影响所有版本的Windows
查看>>
《并行计算的编程模型》一3.8.3 原子交换和条件交换
查看>>