链接: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;
}

  

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

POJ-2349-Arctic Network相关推荐

  1. POJ 2349 Arctic Network (MST中的第K长路)

    题目: http://poj.org/problem?id=2349 1)关于题意,开始code完了,才发现,样例都解释不过去,题意理解错误,最后才明白是求MST种的长度排序后的第K长的权值,这个题意 ...

  2. Arctic Network题解+(最小生成树二次理解 )

    由于在上一篇文章用了大量的文字已经对于最小生成树的两种算法(克鲁斯卡尔和普利姆算法)做了基础的讲解,下面的话我就大概说一下思想和解题步骤,然后再在附加上一个昨天做题(虽然说很基础但是对于初学的我就有点 ...

  3. 【POJ - 2349】【UVA - 10369】 Arctic Network(最小生成树求权值第k大的边)(内附两种算法)

    题干: The Department of National Defence (DND) wishes to connect several northern outposts by a wirele ...

  4. POJ 2236 Wireless Network 并查集

    Wireless Network 并查集 Crawling in process... Crawling failed Time Limit:10000MS     Memory Limit:6553 ...

  5. POJ 3164 Command Network (最小树形图)

    Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 10136   Accepted: 2946 ...

  6. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  7. POJ 3164 Command Network (最小树形图)

    [题目链接]http://poj.org/problem?id=3164 [解题思路]百度百科:最小树形图 ]里面有详细的解释,而Notonlysucess有精简的模板,下文有对其模板的一点解释,前提 ...

  8. POJ 1459 -- Power Network(最大流, 建图)

    题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...

  9. POJ 3164 Command Network

    Description After a long lasting war on words, a war on arms finally breaks out between littleken's ...

  10. poj2349:Arctic Network(最小生成树)

    总时间限制:  2000ms  内存限制:  65536kB 描述 The Department of National Defence (DND) wishes to connect several ...

最新文章

  1. python文件io是啥意思_Python文件IO(普通文件读写)
  2. 初学者python编辑器-分享|Mu 入门:一个面向初学者的 Python 编辑器
  3. php 协程 mysql_实现一个协程版mysql连接池
  4. win10电脑插耳机没声音_教你Win10怎么录制电脑内部声音
  5. ycsb 测试验证模式的mongodb
  6. 如何踢掉 sql 语句中的尾巴,我用 C# 苦思了五种办法
  7. 三十、MySQL 处理重复数据
  8. 纯css实现div中未知尺寸图片的垂直居中
  9. 有人30岁转型做Android开发,老罗android开发视频教程
  10. 卡巴斯基激活试用方法
  11. android 网易视频无法播放器,如何使用网易视频云播放器Android Demo
  12. S7-1500PLC仿真
  13. EditPlus 使用技巧以及快捷键
  14. stm32f103c8t6 最小系统板 制作超简单ST-Link下载器
  15. PS CC2019安装
  16. 给discuz x增加后台菜单管理功能
  17. E 排队(排列组合)[牛客小*白月赛61]
  18. L2-027. 名人堂与代金券
  19. 有实力的APP开发公司应该具备哪些优势?
  20. MantisBT简介

热门文章

  1. Z-BlogPHP海盗导航主题模板zblog5_nav
  2. 弹幕解析播放器json客户端解析后台管理源码
  3. 自动发卡企业商户运营版带WAP手机端+多种主题
  4. SSL 自签证书工具源码
  5. 武汉理工大学转入计算机学院,武汉理工大学计算机学院.doc
  6. [Lottie动画工具 v3.4.4]
  7. 高仿科学刀论坛源码 DZ模板
  8. 9:16 2009-7-30 范型,IList 做为参数
  9. CSS3: 移动端开发中 max-device-width 与 max-width 的区别
  10. 慎用PHP $_REQUEST数组