3078. 【备战NOIP2012图论专项模拟试题】无线通讯网 (Standard IO)
2016-08-18 21:33
429 查看
Description
国防部计划用无线网络连接若干个边防哨所。2种不同的通讯技术用来搭建无线网络:每个边防哨所都要配备无线电收发器;有一些哨所还可以增配卫星电话。任意两个配备了一条卫星电话线路的哨所均可以通话,无论它们相距多远。而只通过无线电收发器通话的哨所之间的距离不能超过D,这是受收发器的功率限制。收发器的功率越高,通话距离D会更远,但同时价格也更贵。
收发器需要统一购买和安装,所以全部哨所只能选择安装一种型号的收发器。换句话说,每一对哨所之间的通话距离都是同一个D。
你的任务是确定收发器必须的最小通话距离D,使得每一对哨所之间至少有一条通话路径(直接的或者间接的)。
Input
第1行:2个整数S(1 <= S <= 100)和P(S < P <= 500),S表示可安装的卫星电话的线路数,P表示边防哨所的数量。接下来P行,每行描述一个哨所的平面坐标(x,y),以km为单位,整数,0<=x,y<=10,000
Output
第1行:1个实数D,表示无线电收发器的最小传输距离。精确到小数点后2位。
Sample Input
2 4 0 100 0 300 0 600 150 750
Sample Output
212.13
Data Constraint
题解
最小生成树,先将每两个点之间的距离算出来,然后从小到大排序,用克鲁斯卡尔,然后第p-s条边就是答案。
代码
type date=record
a,b:longint;
c:real;
end;
var
f,e,u:array[1..5000] of longint;
s:array[0..500000] of date;
function main(t:longint):longint;
begin
if f[t]=t then exit(t);
f[t]:=main(f[t]);
exit(f[t]);
end;
procedure sort(l,r:longint);
var
i,j,w:longint;
mid,t:real;
begin
i:=l;j:=r;
mid:=s[(l+r) div 2].c;
repeat
while s[i].c<mid do inc(i);
while s[j].c>mid do dec(j);
if i<=j then
begin
s[0]:=s[i]; s[i]:=s[j]; s[j]:=s[0];
inc(i);dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
var
i,j,z,x,n,m,w,h:longint;
begin
readln(z,x);
for i:=1 to x do
readln(e[i],u[i]);
n:=0;
for i:=1 to x do
for j:=1 to x do
if i<>j then
begin
inc(n);
s
.a:=i;
s
.b:=j;
s
.c:=sqrt(sqr(e[i]-e[j])+sqr(u[i]-u[j]));
end;
sort(1,n);
for i:=1 to x do
f[i]:=i;
m:=0;n:=0;
while m<x-z do
begin
inc(n);
w:=main(s
.a);
h:=main(s
.b);
if w<>h then
begin
inc(m);
f[w]:=h;
end;
end;
writeln(s
.c:0:2);
end.
相关文章推荐
- 高中纪中OJ3078. 【备战NOIP2012图论专项模拟试题】无线通讯网
- 3076. 【备战NOIP2012图论专项模拟试题】位图 (Standard IO)
- 3077. 【备战NOIP2012图论专项模拟试题】外星人入侵 (Standard IO)
- 3079. 【备战NOIP2012图论专项模拟试题】砍树 (Standard IO)
- 【备战NOIP2012图论专项模拟试题】无线通讯网
- 纪中高中OJ3079. 【备战NOIP2012图论专项模拟试题】砍树题解
- 【备战NOIP2012图论专项模拟试题】砍树
- 【备战NOIP2012图论专项模拟试题】砍树 纪中3079 dfs
- jzoj 3076. 【备战NOIP2012图论专项模拟试题】位图
- 纪中3076【备战NOIP2012图论专项模拟试题】位图 题解
- 【备战NOIP2012图论专项模拟试题】位图
- 【备战NOIP2012图论专项模拟试题】外星人入侵
- 高中纪中OJ3077. 【备战NOIP2012图论专项模拟试题】外星人入侵 题解
- 【备战NOIP2012图论专项模拟试题】砍树
- jzoj3053. 【NOIP2012模拟10.25】旅行 (Standard IO)
- 3066. 【NOIP2012模拟10.29晚】麻将 (Standard IO)
- 3067. 【NOIP2012模拟10.29晚】密码盘 (Standard IO)
- 2016.08.17【初中部 NOIP提高组 】模拟赛C(图论专项模拟试题)
- 【NOIP2011模拟9.3】旅行 (Standard IO)
- 2549. 【NOIP2011模拟9.4】家庭作业 (Standard IO)