比赛 20121106 评测结果 AAAAAAAWAWWW
题目名称 H 指数因子 最终得分 66
用户昵称 Lyre 运行时间 0.004 s
代码语言 Pascal 内存使用 0.22 MiB
提交时间 2012-11-06 10:38:01
显示代码纯文本
program fall;
var a:array [1..111] of string;
    b:array [1..111] of string;
    f,c:array [1..111] of longint;
    tot,i,n,tt,j,head,tail:longint;
    s:string;
    used:array [1..111] of boolean;

procedure qsorts(x,y:longint);
var ba,bb:longint;
    temp,mid:string;
begin
 ba:=x; bb:=y; mid:=b[(x+y) div 2];
 while ba<=bb do
  begin
   while b[ba]<mid do inc(ba);
   while b[bb]>mid do dec(bb);
   if ba<=bb then
    begin temp:=b[ba]; b[ba]:=b[bb]; b[bb]:=temp; end;
   inc(ba); dec(bb);
  end;
 if ba<y then qsorts(ba,y); if bb>x then qsorts(x,bb);
end;

procedure qsort(x,y:longint);
var ba,bb,temp,mid:longint;
begin
 ba:=x; bb:=y; mid:=c[(x+y) div 2];
 while ba<=bb do
  begin
   while c[ba]>mid do inc(ba);
   while c[bb]<mid do dec(bb);
   if ba<=bb then
    begin temp:=c[ba]; c[ba]:=c[bb]; c[bb]:=temp; end;
   inc(ba); dec(bb);
  end;
 if ba<y then qsort(ba,y); if bb>x then qsort(x,bb);
end;

begin
 assign(input,'publish.in');
 assign(output,'publish.out');
 reset(input);
 rewrite(output);
 readln(n); fillchar(used,sizeof(used),false);
 for i:=1 to n do readln(a[i]);
 tot:=n;
 for i:=1 to n do
  begin
   readln(s);
   for j:=1 to n do if s[j]='1' then inc(f[j]);
  end;
 for i:=1 to n do
  if not(used[i]) then
  begin
   tt:=1; c[1]:=f[i];
   for j:=i+1 to n do
    if a[i]=a[j] then begin inc(tt); c[tt]:=f[j]; f[j]:=-1; dec(tot); used[j]:=true; end;
   qsort(1,tt);
   tt:=1;
   while c[tt]>=tt do inc(tt);
   f[i]:=tt-1; used[i]:=true;
  end;
 while tot<>0 do
  for i:=n downto 0 do
   begin
    tail:=0;
    for j:=1 to n do
     if f[j]=i then begin dec(tot); inc(tail); b[tail]:=a[j]; end;
    qsorts(1,tail);
    for j:=1 to tail do writeln(b[j],' ',i);
   end;
 close(input);
 close(output);
end.