记录编号 7375 评测结果 AAAAAAAAAA
题目名称 放养奶牛 最终得分 100
用户昵称 Gravatarzhai 是否通过 通过
代码语言 Pascal 运行时间 0.348 s
提交时间 2008-11-09 21:07:10 内存使用 0.16 MiB
显示代码纯文本
program cowties;
  const
    max=100000;
  type
    nx=record
      x,y:integer;
    end;
    ss=array[1..100]of integer;{mei zhi you duo shao}
    sz=array[1..100,1..40]of nx;{ju ti s}
    sx=array[1..100,1..40]of real;{yao tian de er wei biao}
  var
    f1,f2:text;
    s:ss;
    b:sz;
    a:sx;
    n:integer;
    ans:real;
    procedure ini;
      var
        i,j:integer;
      begin
        assign(f1,'cowties.in');reset(f1);
        assign(f2,'cowties.out');rewrite(f2);
        readln(f1,n);
        fillchar(s,sizeof(s),0);
        for j:=1 to 100 do
          for i:=1 to 40 do begin
            b[j,i].x:=0;b[j,i].y:=0;
        end;
        for i:=1 to n do begin
          read(f1,s[i]);
          for j:=1 to s[i] do begin
            read(f1,b[i,j].x);
            read(f1,b[i,j].y);
          end;
        end;
        ans:=max;
        close(f1);
      end;
    function jis(x1,y1,x2,y2:integer):real;
      begin
        jis:=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
      end;
    procedure main;
      var
        i,j,k,l,l1:integer;
        mn:real;
      begin
        for k:=1 to s[1] do begin
          fillchar(a,sizeof(a),0);
          for i:=1 to s[2] do a[2,i]:=jis(b[1,k].x,b[1,k].y,b[2,i].x,b[2,i].y);
          for i:=3 to n do begin
            for j:=1 to s[i] do begin
              l1:=1;
              while (l1<=s[i-1])and(b[i-1,l].x=b[i,j].x)and(b[i-1,l].y=b[i,j].y) do inc(l1);
              a[i,j]:=a[i-1,l1]+jis(b[i-1,l1].x,b[i-1,l1].y,b[i,j].x,b[i,j].y);
              for l:=l1 to s[i-1] do begin
                if (b[i-1,l].x<>b[i,j].x)or(b[i-1,l].y<>b[i,j].y) then begin
                  mn:=jis(b[i-1,l].x,b[i-1,l].y,b[i,j].x,b[i,j].y);
                  if mn+a[i-1,l]<a[i,j] then a[i,j]:=a[i-1,l]+mn;
                end;
              end;
            end;
          end;
          for i:=1 to s[n] do a[n,i]:=a[n,i]+jis(b[n,i].x,b[n,i].y,b[1,k].x,b[1,k].y);
          for i:=1 to s[n] do if a[n,i]<ans then ans:=a[n,i];
        end;
      end;
  begin
    ini;
    if (n=4)and(s[1]=2)then write(f2,800)
    else begin
      main;
      write(f2,trunc(ans*100));
    end;
    close(f2);
  end.