POJ-2349-Arctic Network
链接:https://vjudge.net/problem/POJ-2349#author=clzls
题意:
思路:
两两求距离,将最小生成树的每条边保存到数组,共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相关推荐
- POJ 2349 Arctic Network (MST中的第K长路)
题目: http://poj.org/problem?id=2349 1)关于题意,开始code完了,才发现,样例都解释不过去,题意理解错误,最后才明白是求MST种的长度排序后的第K长的权值,这个题意 ...
- Arctic Network题解+(最小生成树二次理解 )
由于在上一篇文章用了大量的文字已经对于最小生成树的两种算法(克鲁斯卡尔和普利姆算法)做了基础的讲解,下面的话我就大概说一下思想和解题步骤,然后再在附加上一个昨天做题(虽然说很基础但是对于初学的我就有点 ...
- 【POJ - 2349】【UVA - 10369】 Arctic Network(最小生成树求权值第k大的边)(内附两种算法)
题干: The Department of National Defence (DND) wishes to connect several northern outposts by a wirele ...
- POJ 2236 Wireless Network 并查集
Wireless Network 并查集 Crawling in process... Crawling failed Time Limit:10000MS Memory Limit:6553 ...
- POJ 3164 Command Network (最小树形图)
Command Network Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 10136 Accepted: 2946 ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- POJ 3164 Command Network (最小树形图)
[题目链接]http://poj.org/problem?id=3164 [解题思路]百度百科:最小树形图 ]里面有详细的解释,而Notonlysucess有精简的模板,下文有对其模板的一点解释,前提 ...
- POJ 1459 -- Power Network(最大流, 建图)
题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...
- POJ 3164 Command Network
Description After a long lasting war on words, a war on arms finally breaks out between littleken's ...
- poj2349:Arctic Network(最小生成树)
总时间限制: 2000ms 内存限制: 65536kB 描述 The Department of National Defence (DND) wishes to connect several ...
最新文章
- python文件io是啥意思_Python文件IO(普通文件读写)
- 初学者python编辑器-分享|Mu 入门:一个面向初学者的 Python 编辑器
- php 协程 mysql_实现一个协程版mysql连接池
- win10电脑插耳机没声音_教你Win10怎么录制电脑内部声音
- ycsb 测试验证模式的mongodb
- 如何踢掉 sql 语句中的尾巴,我用 C# 苦思了五种办法
- 三十、MySQL 处理重复数据
- 纯css实现div中未知尺寸图片的垂直居中
- 有人30岁转型做Android开发,老罗android开发视频教程
- 卡巴斯基激活试用方法
- android 网易视频无法播放器,如何使用网易视频云播放器Android Demo
- S7-1500PLC仿真
- EditPlus 使用技巧以及快捷键
- stm32f103c8t6 最小系统板 制作超简单ST-Link下载器
- PS CC2019安装
- 给discuz x增加后台菜单管理功能
- E 排队(排列组合)[牛客小*白月赛61]
- L2-027. 名人堂与代金券
- 有实力的APP开发公司应该具备哪些优势?
- MantisBT简介
热门文章
- Z-BlogPHP海盗导航主题模板zblog5_nav
- 弹幕解析播放器json客户端解析后台管理源码
- 自动发卡企业商户运营版带WAP手机端+多种主题
- SSL 自签证书工具源码
- 武汉理工大学转入计算机学院,武汉理工大学计算机学院.doc
- [Lottie动画工具 v3.4.4]
- 高仿科学刀论坛源码 DZ模板
- 9:16 2009-7-30 范型,IList 做为参数
- CSS3: 移动端开发中 max-device-width 与 max-width 的区别
- 慎用PHP $_REQUEST数组