- 题解
- 2015-05-29 17:16:56 @
本题是一道图论题,我用的是Dijkstra(未用堆优化),具体思路参考了以前的一篇题解,
“注意不同点的代价是不同的
起点矩阵中一点——>起点矩阵中一点 代价为0
某矩阵一点——>同矩阵一点 代价为两点欧几里得距离*高速路价
某矩阵一点——>另矩阵一点 代价为两点欧几里得距离*航线价
终点矩阵中一点——>终点矩阵中一点 代价为0”——引自et.bug
这里特别感谢
这题初始化稍微烦了一点,其他并不难
附上代码
var
n,t,a,b,c,i,j,k1,k2,k,a1,b1:longint;
min:real;
x,y:array[1..4,1..100]of longint;
visit:array[1..400]of longint;
v:array[1..100]of longint;
d:array[1..400]of real;
map:array[1..400,1..400]of real;
begin
read(n,t,a1,b1);
fillchar(map,sizeof(map),0);
for i:=1 to n do
begin
read(x[1,i],y[1,i],x[2,i],y[2,i],x[3,i],y[3,i],v[i]);
a:=(abs(x[1,i]-x[2,i]))*(abs(x[1,i]-x[2,i]))+abs(y[1,i]-y[2,i])*abs(y[1,i]-y[2,i]);
b:=(abs(x[1,i]-x[3,i]))*(abs(x[1,i]-x[3,i]))+abs(y[1,i]-y[3,i])*abs(y[1,i]-y[3,i]);
c:=(abs(x[2,i]-x[3,i]))*(abs(x[2,i]-x[3,i]))+abs(y[2,i]-y[3,i])*abs(y[2,i]-y[3,i]);
for j:=1 to 3 do
begin
if j=1
then
begin
if a+b=c
then
begin
x[4,i]:=x[2,i]-x[1,i]+x[3,i];
y[4,i]:=y[2,i]-y[1,i]+y[3,i];
end;
end;
if j=2
then
begin
if a+c=b
then
begin
x[4,i]:=x[3,i]-x[2,i]+x[1,i];
y[4,i]:=y[3,i]-y[2,i]+y[1,i];
end;
end;
if j=3
then
begin
if b+c=a
then
begin
x[4,i]:=x[2,i]-x[3,i]+x[1,i];
y[4,i]:=y[2,i]-y[3,i]+y[1,i];
end;
end;
end;
end;
for i:=1 to n*4 do
for j:=1 to n*4 do
begin
if i<>j
then
begin
if (((i-1)div 4+1=a1)and((j-1) div 4+1=a1))or(((i-1)div 4+1=b1)and((j-1) div 4+1=b1))
then map[i,j]:=0
else
begin
if (i-1) div 4+1=(j-1) div 4+1
then
begin
k1:=abs(x[(i-1)mod 4+1,(i-1) div 4+1]-x[(j-1)mod 4+1,(j-1) div 4+1]);
k2:=abs(y[(i-1)mod 4+1,(i-1) div 4+1]-y[(j-1)mod 4+1,(j-1) div 4+1]);
map[i,j]:=sqrt(k1*k1+k2*k2)*v[(i-1) div 4+1];
map[j,i]:=map[i,j];
end
else
begin
k1:=abs(x[(i-1)mod 4+1,(i-1) div 4+1]-x[(j-1)mod 4+1,(j-1) div 4+1]);
k2:=abs(y[(i-1)mod 4+1,(i-1) div 4+1]-y[(j-1)mod 4+1,(j-1) div 4+1]);
map[i,j]:=sqrt(k1*k1+k2*k2)*t;
map[j,i]:=map[i,j];
end;
end;
end;
end;
for i:=1 to 4*n do d[i]:=1000000000;
d[1]:=0;
k1:=1;
fillchar(visit,sizeof(visit),0);
visit[1]:=1;
for i:=1 to 4*n-1 do
begin
visit[k1]:=1;
k:=k1;
min:=1000000000;
for j:=1 to 4*n do
begin
if (j<>k)and(visit[j]=0)
then
if d[j]>d[k]+map[j,k]
then
begin
d[j]:=d[k]+map[j,k];
end;
end;
for j:=1 to 4*n do
begin
if (min>d[j])and(visit[j]=0)
then
begin
min:=d[j];
k1:=j;
end;
end;
end;
writeln(d[4*b1]:0:2);
end.