记录编号 |
7261 |
评测结果 |
AAWWWWWWWA |
题目名称 |
放养奶牛 |
最终得分 |
30 |
用户昵称 |
苏轼 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.038 s |
提交时间 |
2008-11-07 17:42:12 |
内存使用 |
0.17 MiB |
显示代码纯文本
program cch(input,output);
const
maxf=10000000000000;
type
sz=record
x:array[1..40] of integer;
y:array[1..40] of integer;
num:integer;
end;
var
i,n,j,s,k:integer;
a:array[1..101] of sz;
f:array[1..101,1..40] of real;
b:array[1..101,1..40] of integer;
tmp,ans:real;
function check(c,h,k:integer):boolean;
var
i,j:integer;
begin
if (a[c].x[h]=a[c-1].x[k])and(a[c].y[h]=a[c-1].y[k]) then exit(false);
j:=k;
for i:=c-1 downto 2 do
begin
j:=b[i,j];
if (a[c].x[h]=a[i-1].x[j])and(a[c].y[h]=a[i-1].y[j]) then exit(false);
end;
exit(true);
end;
begin
assign(input,'cowties.in');
assign(output,'cowties.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
begin
read(s);
for j:=1 to s do read(a[i].x[j],a[i].y[j]);
a[i].num:=s;
end;
for i:=1 to 40 do f[1,i]:=0;
for i:=2 to n do
for j:=1 to a[i].num do
begin
f[i,j]:=maxf;
for k:=1 to a[i-1].num do
begin
tmp:=f[i-1,k]+sqrt(sqr(a[i-1].x[k]-a[i].x[j])+sqr(a[i-1].y[k]-a[i].y[j]));
if (tmp<f[i,j]) and check(i,j,k) then
begin
f[i,j]:=tmp; b[i,j]:=k;
end;
end;
end;
for i:=1 to a[n].num do
begin
k:=i;
for j:=n downto 2 do k:=b[j,k];
f[n,i]:=f[n,i]+sqrt(sqr(a[1].x[k]-a[n].x[i])+sqr(a[1].y[k]-a[n].y[i]));
end;
ans:=maxf;
for i:=1 to a[n].num do
if ans>f[n,i] then
ans:=f[n,i];
write(trunc(ans*100));
close(input);
close(output);
end.