记录编号 53237 评测结果 EEEEEEEEEE
题目名称 [HAOI 2006]均分数据 最终得分 0
用户昵称 Gravatarironcircle 是否通过 未通过
代码语言 Pascal 运行时间 0.931 s
提交时间 2013-02-23 08:42:14 内存使用 0.17 MiB
显示代码纯文本
program zx00;
  var
    f,w,s,q:array[0..20] of longint;
    ans,tot,temp,st,t:double;
    delta,time,new,now,n,i,m,j,k,k1,k2,k3,k4,l:longint;
  function judge:longint;
  var i,j:longint;
  begin
    judge:=0;
    fillchar(w,sizeof(w),0);
    for i:=1 to n do inc(w[s[i]],f[i]);
    for i:=1 to m do judge:=judge+sqr(w[i]);
  end;
  begin
    assign(input,'data.in');
    reset(input);
    assign(output,'data.out');
    rewrite(output);
    randomize;
    readln(n,m);
    for i:=1 to n do read(f[i]);
    readln;
    k:=n div m;
    for i:=0 to m-1 do
      begin
        for j:=1 to k do
          s[i*k+j]:=i+1;
      end;
    for i:=m*k+1 to n do s[i]:=m;
    now:=judge;
    st:=15;
    time:=1;
    temp:=st;
    while time<300000 do
    begin
      q:=s;
      k1:=random(n)+1;k2:=random(n)+1;
      k3:=random(m)+1;k4:=random(m)+1;
      s[k1]:=k3;s[k2]:=k4;
      new:=judge;
      delta:=now-new;
      if (now>new)or(random<exp(delta/temp)) then now:=new else
      begin
       s:=q;
      end;
      inc(time);
      temp:=st/ln(time)*ln(2);
    end;
   fillchar(w,sizeof(w),0);
   for i:=1 to n do
   begin
     tot:=tot+f[i];
     inc(w[s[i]],f[i]);
   end;
   tot:=tot/m;
   for i:=1 to m do ans:=ans+(w[i]-tot)*(w[i]-tot);
  // for i:=1 to n do write(s[i],' ');
   ans:=sqrt(ans/m);
   writeln(ans:0:2);
   close(input);close(output);
  end.