分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

POJ-2349-Arctic Network

发布时间:2023-09-06 02:32责任编辑:郭大石关键词:暂无标签

链接:https://vjudge.net/problem/POJ-2349#author=clzls

题意:

国防部(DND)要用无线网络连接北部几个哨所。两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫星频道。
任何两个有卫星信道的哨所可以通过卫星进行通信,而不管他们的位置。同时,当两个哨所之间的距离不超过D时可以通过无线电通讯,D取决于对收发器的功率。功率越大,D也越大,但成本更高。出于采购和维修的方便,所有哨所的收发器必须是相同的;那就是说,D值对每一个哨所相同。
 
你的任务是确定收发器的D的最小值。每对哨所间至少要有一条通信线路(直接或间接)。

思路:

两两求距离,将最小生成树的每条边保存到数组,共p-1条边,s个卫星形成s-1条边。

较大s-1条边 使用微型,答案即a[p-s]。

代码:

#include <iostream>#include <memory.h>#include <string>#include <istream>#include <sstream>#include <vector>#include <stack>#include <algorithm>#include <map>#include <queue>#include <math.h>#include <cstdio>using namespace std;typedef long long LL;const int MAXM = 250000+10;const int MAXN = 500+10;struct Node{ ???double _x,_y;}node[MAXN];struct Path{ ???int _l,_r; ???double _value; ???bool operator < (const Path & that)const{ ???????return this->_value < that._value; ???}}path[MAXM];int Father[MAXN];double a[MAXN];int n;int s,p;int Get_F(int x){ ???return Father[x] = (Father[x] == x) ? x : Get_F(Father[x]);}void Init(){ ???for (int i = 1;i <= n;i++) ???????Father[i] = i;}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));}int main(){ ???cin >> n; ???while (n--) ???{ ???????memset(a,0,sizeof(a)); ???????cin >> s >> p; ???????for (int i = 1;i <= p;i++) ???????????Father[i] = i; ???????for (int i = 1;i <= p;i++) ???????????cin >> node[i]._x >> node[i]._y; ???????int pos = 0; ???????for (int i = 1;i <= p;i++) ???????{ ???????????for (int j = i + 1;j <= p;j++) ???????????{ ???????????????path[++pos]._l = i; ???????????????path[pos]._r = j; ???????????????path[pos]._value = Get_Len(node[i], node[j]); ???????????} ???????} ???????sort(path + 1,path + 1 + pos); ???????int cnt = 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; ???????????????a[++cnt] = path[i]._value; ???????????} ???????} ???????printf("%.2lf\n",a[p-s]); ???} ???return 0;}

  

POJ-2349-Arctic Network

原文地址:https://www.cnblogs.com/YDDDD/p/10338933.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved