sort3.pas

来自「Magio牛的usaco源代码」· PAS 代码 · 共 41 行

PAS
41
字号
{
ID:maigoak1
PROG:sort3
}

program sort3;
var
  fin,fout:text;
  count:array[1..3]of integer;
  wrong:array[1..3,1..3]of integer;
    {wrong[i,j] means the number of the i's in j's places}
  n,x,i,j:integer;
function min(a,b:integer):integer;
  begin
    if a<b then min:=a else min:=b;
  end;
begin
  fillchar(count,sizeof(count),0);
  fillchar(wrong,sizeof(wrong),0);
  assign(fin,'sort3.in');
  reset(fin);
  readln(fin,n);
  for i:=1 to n do begin
    readln(fin,x);
    inc(count[x]);
  end;
  reset(fin);
  readln(fin);
  for i:=1 to 3 do
    for j:=1 to count[i] do begin
      readln(fin,x);
      inc(wrong[x,i]);
    end;
  close(fin);

  assign(fout,'sort3.out');
  rewrite(fout);
  writeln(fout,min(wrong[1,2],wrong[2,1])+min(wrong[1,3],wrong[3,1])+min(wrong[2,3],wrong[3,2])+2*abs(wrong[1,2]-wrong[2,1]));
  close(fout);
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?