Luogu P1991 无线通讯网
P1991 无线通讯网
题目描述
国防部计划用无线网络连接若干个边防哨所。2 种不同的通讯技术用来搭建无线网络;
每个边防哨所都要配备无线电收发器;有一些哨所还可以增配卫星电话。
任意两个配备了一条卫星电话线路的哨所(两边都ᤕ有卫星电话)均可以通话,无论
他们相距多远。而只通过无线电收发器通话的哨所之间的距离不能超过 D,这是受收发器
的功率限制。收发器的功率越高,通话距离 D 会更远,但同时价格也会更贵。
收发器需要统一购买和安装,所以全部哨所只能选择安装一种型号的收发器。换句话
说,每一对哨所之间的通话距离都是同一个 D。你的任务是确定收发器必须的最小通话距
离 D,使得每一对哨所之间至少有一条通话路径(直接的或者间接的)。
输入输出格式
输入格式:
从 wireless.in 中输入数据第 1 行,2 个整数 S 和 P,S 表示可安装的卫星电话的哨所
数,P 表示边防哨所的数量。接下里 P 行,每行两个整数 x,y 描述一个哨所的平面坐标
(x, y),以 km 为单位。
输出格式:
输出 wireless.out 中
第 1 行,1 个实数 D,表示无线电收发器的最小传输距离,㋮确到小数点后两位。
输入输出样例
2 4
0 100
0 300
0 600
150 750
212.13
说明
附送样例一个
对于 20% 的数据:P = 2,S = 1
对于另外 20% 的数据:P = 4,S = 2
对于 100% 的数据保证:1 ≤ S ≤ 100,S < P ≤ 500,0 ≤ x,y ≤ 10000。
感觉图论的题目难度都好假
=================================================
既然有S个点可以建卫星电话,那么我们可以默认已经有S个节点是相连的,那么这S个节点就变成了1个节点
那么问题就变为求一张有P-S+1个节点的图的最小生成树
Kruskal果断水过
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> const int maxn = 507; using namespace std; int s, p, cnt, f[maxn], tot;
double ans; struct Node {
int x, y;
}node[maxn]; struct Edge {
int u, v;
double w;
}ed[maxn*maxn]; inline int read() {
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0'; c = getchar();
}
return x * f;
} int find(int x) {
if(x == f[x]) return f[x];
else return f[x] = find(f[x]);
} bool cmp(Edge a, Edge b) {
return a.w < b.w;
} int main() {
s = read(); p = read();
for(int i=1; i<=p; i++) {
node[i].x = read(), node[i].y = read();
}
for(int i=1; i<=p; i++) {
f[i] = i;
}
for(int i=1; i<=p; i++)
for(int j=1; j<=p; j++)
if(i != j) {
ed[++cnt].u = i, ed[cnt].v = j;
int x1 = node[i].x, y1 = node[i].y, x2 = node[j].x, y2 = node[j].y;
ed[cnt].w = sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}
sort(ed+1, ed+1+cnt, cmp);
for(int i=1; i<=cnt; i++) {
int xx = find(ed[i].u), yy = find(ed[i].v);
if(xx != yy) {
f[xx] = find(yy);
tot ++;
ans = ed[i].w;
}
if(tot == p-s) {
break;
}
}
printf("%.2lf", ans);
}
最新文章
- 读《高性能javascript》笔记(一)
- sublime代码片段
- HBA相关知识
- java内存模型-基础
- NYOJ:题目860 又见01背包
- Linux中如何查看文件的最初创建时间
- Python:变量与字符串
- android studio上代码编译调试中遇到的一些异常记录
- codeforces 659E . New Reform 强连通
- 解决了clang: error: linker command failed with exit code 1 (use -v to see invocation)&#160;解决方法
- 【转】 Android项目的mvc模式
- 锐捷Linux版的下载和使用(福大客户端)
- IIS7配置伪静态把后缀名映射为html
- zabbix学习笔记----概念----2019.03.25
- SogouCloud.exe进程导致SQL Server服务无法启动
- cf 1110 D
- !!代码:baidu 分享
- Android 使用 NYTimes Stores 缓存 network request
- PCL采样一致性算法
- TransitiveClosure
热门文章
- Windows10、ARM开发板、VMware虚拟机同时连接Internet
- HDU 5371(2015多校7)-Hotaru&;#39;s problem(Manacher算法求回文串)
- 协议解析Bug分析
- POJ 2562:Primary Arithmetic
- POJ 2260:Error Correction
- Ural1099 Work Scheduling 一般图的最大匹配
- jquery对所有<;input type=";text";的控件赋值
- restful api 错误
- Linux学习笔记之Linux系统启动过程
- mysqlbinlog(日志管理工具)