记录编号 11365 评测结果 DDDDDDDDDD
题目名称 速配游戏(无数据) 最终得分 0
用户昵称 Gravatarmaxiem 是否通过 未通过
代码语言 Pascal 运行时间 0.052 s
提交时间 2009-07-27 21:45:48 内存使用 4.01 MiB
显示代码纯文本
program match;
var
  woman,man:array [1..1000,1..1000] of integer;
  time,best,ko:array [1..1000] of integer;
  flag:boolean;
  n,i,j:integer;
begin
  fillchar (man,sizeof(man),0);
  fillchar (woman,sizeof(woman),0);
  fillchar (ko,sizeof(ko),0);
  assign (input,'match.in');
  reset (input);
  readln (n);
  for i:=1 to n do begin
    for j:=1 to n do read (man[i,j]);
    readln;
  end;
  for i:=1 to n do begin
    for j:=1 to n do read (woman[i,j]);
    readln;
  end;
  repeat
    fillword (best,sizeof(best) div 2,n+1);
    fillchar (time,sizeof(time),0);flag:=true;
    for i:=1 to n do begin
      inc(time[man[i,ko[i]+1]]);
      if time[man[i,ko[i]+1]]<>1 then flag:=false;
      for j:=1 to n do if (woman[man[i,ko[i]+1],j]=i) and (j<best[man[i,ko[i]+1]]) then begin
        if best[man[i,ko[i]+1]]<=n then inc(ko[woman[man[i,ko[i]+1],best[man[i,ko[i]+1]]]]);
        best[man[i,ko[i]+1]]:=j;
        break;
      end;
      if woman[man[i,ko[i]+1],best[man[i,ko[i]+1]]]<>i then inc(ko[i]);
    end;
  until flag;
  close (input);
  assign (output,'match.out');
  rewrite (output);
  for i:=1 to n do writeln (woman[i,best[i]]);
  close (output);
end.