记录编号 4567 评测结果 AATTAAAATA
题目名称 [NOI 1999]棋盘分割 最终得分 70
用户昵称 Gravatar辨机ZN 是否通过 未通过
代码语言 Pascal 运行时间 6.509 s
提交时间 2008-10-20 22:03:34 内存使用 0.11 MiB
显示代码纯文本
program ex(f1,f2);
 const
  maxn=15;
 type
  ka=record
   x1,y1,x2,y2:integer;
  end;
  zn=array [0..maxn] of ka;
  da=ka;
  la=array [1..8,1..8] of integer;
  fa=array [1..maxn] of real;
 var
  a:zn; f1,f2:text; map:la;
  i,j,k,m,n,p,l,x:integer;
  ans,tot:real; f:fa; c:da;
 procedure print(d:zn);
  var
   i,j,k,p,t:integer; pj,zong:real;
  begin
   for k:=1 to n do
    begin
     l:=0;
     for i:=d[k].x1 to d[k].x2 do
      for j:=d[k].y1 to d[k].y2 do
       l:=l+map[i,j];
     f[k]:=l;
    end;
    pj:=0;
    for i:=1 to n do pj:=pj+f[i];
    pj:=pj/n;
    zong:=0;
    for i:=1 to n do zong:=zong+(f[i]-pj)*(f[i]-pj);
    zong:=zong/n;
    if zong<ans then ans:=zong;
  end;


 procedure search(step:integer);
  var
   i,j,k:integer;
   c:da;
  begin
   for k:=1 to step-1 do
    begin
     c:=a[k];
     for i:=c.x1+1 to c.x2 do
      begin
       a[step].x1:=i; a[step].y1:=c.y1;
       a[step].x2:=c.x2; a[step].y2:=c.y2;
       a[k].x2:=i-1;
       if step=n then print(a)
                 else search(step+1);
       a[k].x2:=c.x2;
      end;
     for j:=c.y1+1 to c.y2 do
      begin
       a[step].x1:=c.x1; a[step].y1:=j;
       a[step].x2:=c.x2; a[step].y2:=c.y2;
       a[k].y2:=j-1;
       if step=n then print(a)
                 else search(step+1);
       a[k].y2:=c.y2;
      end;
    end;
  end;
 begin
  assign(f1,'division.in'); reset(f1);
  assign(f2,'division.out'); rewrite(f2);
  readln(f1,n);
  ans:=100000;
  for i:=1 to 8 do
   for j:=1 to 8 do read(f1,map[i,j]);
  a[1].x1:=1; a[1].y1:=1; a[1].x2:=8; a[1].y2:=8;
  search(2);
  ans:=sqrt(ans);
  writeln(f2,ans:0:3);
  close(f1);
  close(f2);
 end.