记录编号 2363 评测结果 WATTWAAWTA
题目名称 [NOI 1999]棋盘分割 最终得分 40
用户昵称 Gravatarelysian 是否通过 未通过
代码语言 Pascal 运行时间 6.519 s
提交时间 2008-09-19 18:55:23 内存使用 0.11 MiB
显示代码纯文本
program yuffie;
const
fin='division.in';fout='division.out';
var
f1,f2:text;
calcu,fangcha,ans,aver:real;
n,sum:longint;
a:array[0..9,0..9] of integer;
p:array[1..15] of record
                        x1,y1,x2,y2:integer;
                        end;

procedure min;
var
sum1:real;
i,x,y,aa,b,count:longint;
begin
calcu:=0;
sum1:=0;
for i:=1 to n do
begin
  count:=0;
  for x:=p[i].x1 to p[i].x2-1 do
  for y:=p[i].y1 to p[i].y2-1 do
     count:=count+a[x,y];
sum1:=sum1+(count-aver)*(count-sum);
end;

fangcha:=sqrt(  sum1/n  );
if fangcha<ans then ans:=fangcha;
end;

procedure main(a:integer);
var
x,y,r:integer;
begin
if a=n then begin min;exit;end;
for r:=1 to a do
begin
  for x:=p[r].x1+1 to p[r].x2-1 do
    begin
     p[a+1].x1:=x;p[a+1].y1:=p[r].y1;
     p[a+1].x2:=p[r].x2;p[a+1].y2:=p[r].y2;
     p[r].x2:=x;
     main(a+1);
     p[r].x2:=p[a+1].x2;
    end;
  for y:=p[r].y1+1 to p[r].y2-1 do
    begin
    p[a+1].x1:=p[r].x1;p[a+1].y1:=y;
    p[a+1].x2:=p[r].x2;p[a+1].y2:=p[r].y2;
    p[r].y2:=y;
    main(a+1);
    p[r].y2:=p[a+1].y2;
    end;
 end;

end;

procedure init;
var
i,j:longint;
begin
 assign(f1,fin);reset(f1);
 readln(f1,n);
 for i:=1 to 8 do
 for j:=1 to 8 do
 begin
 read(f1,a[i,j]);
 sum:=sum+a[i,j];
 end;
 aver:=sum/n;
p[1].x1:=1;p[1].y1:=1;p[1].x2:=9;p[1].y2:=9;
ans:=maxlongint;
close(f1);
end;


BEGIN
init;
main(1);
assign(f2,fout);rewrite(f2);
writeln(f2,round(ans*1000)/1000);
close(f2);
END.