记录编号 4853 评测结果 AATTAAAATA
题目名称 [NOI 1999]棋盘分割 最终得分 70
用户昵称 Gravatarzpl123 是否通过 未通过
代码语言 Pascal 运行时间 6.509 s
提交时间 2008-10-22 21:00:40 内存使用 0.11 MiB
显示代码纯文本
program division;
type
fa=record
        x1:integer;
        y1:integer;
        x2:integer;
        y2:integer;
   end;


var
x:array[1..15]of fa;
y:array[1..8,1..8] of real;
n:integer;
ave,sum,ans:real;

procedure init;
var
i,j:integer;
begin
assign(input,'division.in');
reset(input);
assign(output,'division.out');
rewrite(output);

readln(n);
for i:=1 to 8 do
 begin
 for j:=1 to 8 do
 read(y[i,j]);
 readln;
 end;
x[1].x1:=1; x[1].y1:=1;
x[1].x2:=8; x[1].y2:=8;

close(input);

for i:=1 to 8 do
 for j:=1 to 8 do sum:=sum+y[i,j];
ave:=sum/n;
ans:=maxint;
end;


procedure s;
var
i,j,d:integer;
a,b:real;
begin
a:=0;

for i:=1 to n do
 begin
 b:=0;
 for j:=x[i].x1 to x[i].x2 do
  for d:=x[i].y1 to x[i].y2 do
  b:=b+y[j,d];
 a:=a+(b-ave)*(b-ave);
 end;

a:=sqrt(a/n);

if a<=ans then ans:=a;
end;

procedure try(k:integer);
var
i,j,temp:integer;

begin
 for i:=1 to k-1 do
  begin
  for j:=x[i].x1 to x[i].x2-1 do
   begin
   temp:=x[i].x2;
   x[k].x1:=j+1;
   x[k].y1:=x[i].y1;
   x[k].x2:=x[i].x2;
   x[k].y2:=x[i].y2;
   x[i].x2:=j;
   if k=n then s else try(k+1);
   x[i].x2:=temp;
   end;
  for j:=x[i].y1 to x[i].y2-1 do
   begin
   temp:=x[i].y2;
   x[k].x1:=x[i].x1;
   x[k].y1:=j+1;
   x[k].x2:=x[i].x2;
   x[k].y2:=x[i].y2;
   x[i].y2:=j;
   if k=n then s else try(k+1);
   x[i].y2:=temp;
   end;
  end;
end;

begin
init;
try(2);
writeln(ans:0:3);
close(output);
end.