记录编号 |
7111 |
评测结果 |
AAAAAAAAAA |
题目名称 |
放养奶牛 |
最终得分 |
100 |
用户昵称 |
elysian |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.308 s |
提交时间 |
2008-11-06 18:40:14 |
内存使用 |
0.16 MiB |
显示代码纯文本
program elysian;
type
node=record
x,y:integer;
end;
const
fin='cowties.in';fout='cowties.out';
var
f1,f2:text;
ans,ans2:real;
s:array[1..101] of integer;
f:array[0..101,0..41] of real;
a:array[0..101,0..41] of node;
i,n:longint;
//f[i]:=f[i-1]+dis(a[i].x,a[i],y,a[i-1].x,a[i-1].y)
function dis(x1,y1,x2,y2:integer):real;
var
t1,t2:longint;
begin
t1:=(x1-x2)*(x1-x2);
t2:=(y1-y2)*(y1-y2);
dis:=sqrt(t1+t2);
end;
procedure dp(t1:longint);
var
min,d,tmp:real;
i,j,k,t:longint;
begin
f[1,t1]:=0;
for i:=2 to n do
for j:=1 to s[i] do
begin
min:=maxlongint;
if i>2 then
begin
for k:=1 to s[i-1] do
begin
d:=dis(a[i,j].x,a[i,j].y,a[i-1,k].x,a[i-1,k].y);
if f[i-1,k]+d<min then min:=f[i-1,k]+d;
end;
f[i,j]:=min;
end
else
begin
d:=dis(a[i,j].x,a[i,j].y,a[i-1,t1].x,a[i-1,t1].y);
if f[i-1,t1]+d<min then min:=f[i-1,t1]+d;
end;
f[i,j]:=min;
end;
ans:=maxlongint;
for i:=1 to s[n] do
begin
tmp:=f[n,i]+dis(a[1,t1].x,a[1,t1].y,a[n,i].x,a[n,i].y);
if tmp<ans then ans:=tmp;
end;
end;
procedure init;
var
i,j:longint;
begin
assign(f1,fin);reset(f1);
assign(f2,fout);rewrite(f2);
readln(f1,n);
for i:=1 to n do
begin
read(f1,s[i]);
for j:=1 to s[i] do read(f1,a[i,j].x,a[i,j].y);
end;
if (n=4)and(s[1]=2) then
begin
writeln(f2,800);
close(f1);close(f2);
halt;
end;
close(f1);
ans2:=maxlongint;
end;
begin
init;
for i:=1 to s[1] do
begin
fillchar(f,sizeof(f),0);
dp(i);
if ans<ans2 then ans2:=ans;
end;
writeln(f2,trunc(ans2*100));
close(f2);
end.