记录编号 7092 评测结果 AAAAAAAAAA
题目名称 放养奶牛 最终得分 100
用户昵称 Gravatar辨机ZN 是否通过 通过
代码语言 Pascal 运行时间 0.296 s
提交时间 2008-11-06 16:26:47 内存使用 0.16 MiB
显示代码纯文本
program ex(f1,f2);
 type
  ca=record
   x,y:integer;
  end;
  la=array [1..101] of integer;
  zn=array [1..101,0..40] of ca;
  ka=array [1..101,0..40] of real;
 var
  a:zn; w,p,ans,fin:real;
  f1,f2:text; c:ka; s:la;
  i,j,k,m,n,b,l,t,v,q:longint;
 function juli(x1,y1,x2,y2:integer):real;
  begin
   juli:=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  end;

 begin
  assign(f1,'cowties.in'); reset(f1);
  assign(f2,'cowties.out'); rewrite(f2);
  readln(f1,n);
  fin:=9999999;
  for i:=1 to n do
   begin
    read(f1,b); s[i]:=b;
     for j:=1 to b 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;
 for q:=1 to s[1] do
  begin
  for i:=1 to s[2] do
   c[2,i]:=juli((a[2,i].x),(a[2,i].y),(a[1,q].x),(a[1,q].y));

  for t:=3 to n do
   for i:=1 to s[t] do
    begin
     w:=9999999;
     for j:=1 to s[t-1] do
      begin
       p:=juli(a[t,i].x,a[t,i].y,a[t-1,j].x,a[t-1,j].y)+c[t-1,j];
       if p<w then w:=p;
      end;
     c[t,i]:=w;
    end;
   ans:=9999999;
   for j:=1 to s[n] do
    begin
     w:=9999999;
     p:=juli(a[1,q].x,a[1,q].y,a[n,j].x,a[n,j].y)+c[n,j];
     if p<w then w:=p;
     if w<ans then ans:=w;
    end;
  if ans<fin then fin:=ans;
 end;
 writeln(f2,trunc(fin*100));
 close(f1);
 close(f2);
end.