【求注释】学霸,教我深搜广搜。大神,给我注释一下可好,注释!
pascal吧
全部回复
仅看楼主
level 2
玲久R 楼主
2015年07月19日 11点07分 1
level 2
玲久R 楼主
const
mx=30;
var
p:array[1..mx,1..2] of integer;
d:array[1..mx,1..mx] of real;
n,i,j.last:integer;
ans,cur:real;
ansp,curp:array[1..mx] of integer
used:array[1..mx] of boolean;
procedure dfs(k:integer);
var next:integer;
begin
for next:=1 to n do if not used[next] then
begin
if next=last then
begin
dec(last);
while used[last] do dec(last);
if last<i then break;
end;
if cur+d[curp[k-1]][next]<ans then
begin
curp[k]:=next;
cur:=cur+d[curp[k-1]][next];
used[next]:=true;
if k<n-1 then dfs(k+1)
else
begin
if cur+d[curp[k]][last]<ans then
begin
curp[n]:=last;ans:=cur+d[curp[k]][last];
ansp:=curp;
end;
end;
cur:=cur-d[curp[k-1]][next];
used[next]:=false;
if next>last then last:=next;
end;
end;
end;
begin
readln(n);
for i:=1 to n do readln(p[i,1],p[i,2]);
for i:=1 to n-1 do
for j:=i+1 to n do
begin
d[i,j]:=aqrt((p[i,1]-p[j,1])*(p[i,1]-p[j,1]))+(p[i,2]-p[j,2])*(p[i,2]-p[j,2]));
d[j,i]:=d[i,j];
end;
ans:=0;
for i:=1 to n-1 do
begin
ans:=ans+s[i,i+1];
ansp[i]:=i;
end;
ansp[n]:=n;
for i:=1 to n-1 do
begin
cur:=0;
curp[1]:=i;
fillchar(used,sizeof(used),false);
used[i]:=true;
last;=n;
dfs(2);
end;
writeln(ans:0:4);
for i:=1 to n-1 do write(ansp[i],' ');
writeln(ansp[n]);
end.
2015年07月19日 11点07分 2
level 12
我就问问是不是WL的?是不是SZ的?是不是明天要讲?什么?是!那么……我把电子书弄丢了,速速发给我……
2015年07月19日 13点07分 4
level 14
先O(n^2)预处理出各PC的距离,建图。
然后将距离从小到大排序,每次加边后并查集合并,加到n-1次为止。
以上是简单的Kruskal算法。
此外个人认为不太好的Prim算法,但对此题的稠密图比较有作用。
先随便找个点,之后依次找与当前找的点距离最近的点并放到树上,n-1次即可。
2015年07月19日 13点07分 6
谢谢大神[开心]
2015年07月19日 14点07分
level 9
另←_←直接发代码很少有人看的←_←
2015年07月23日 11点07分 7
1