比赛 |
HAOI2009 模拟试题1 |
评测结果 |
WWWWTEEEEE |
题目名称 |
洞窟探索 |
最终得分 |
0 |
用户昵称 |
辨机ZN |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-04-21 11:09:53 |
显示代码纯文本
program ex(f1,f2);
type
zn=array [1..150,1..150] of longint;
ka=array [1..150] of longint;
fa=array [1..150] of longint;
pa=array [1..150,1..150] of boolean;
la=array [1..100000] of longint;
var
f1,f2:text;
i,j,k,p,m,n,l,x,y,ans,now,tot:longint;
flag:pa;
pj:real;
a:zn;
d:ka;
c:fa;
f:la;
procedure qsort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l; j:=r;
x:=f[(l+r) div 2];
repeat
while f[i]<x do inc(i);
while f[j]>x do dec(j);
if i<=j then
begin
y:=f[i];
f[i]:=f[j];
f[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if r>i then qsort(i,r);
end;
begin
ans:=maxlongint;
assign(f1,'hole.in'); reset(f1);
assign(f2,'hole.out'); rewrite(f2);
readln(f1,n,m);
for i:=1 to n do
for j:=1 to n do
flag[i,j]:=true;
for i:=1 to n do
for j:=1 to n do
a[i,j]:=99999;
for i:=1 to n-1 do
begin
readln(f1,x,y,l);
a[x,y]:=l;
a[y,x]:=l;
end;
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if a[i,j]>(a[i,k]+a[k,j]) then a[i,j]:=a[i,k]+a[k,j];
now:=0;
for i:=1 to n do
for j:=i+1 to n do
if i<>j then
begin inc(now); f[now]:=a[i,j]; end;
qsort(1,now);
for i:=1 to m do tot:=tot+f[i];
pj:=tot/m;
writeln(f2,pj:0:2);
close(f1); close(f2);
end.