⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sort3.pas

📁 Magio牛的usaco源代码
💻 PAS
字号:
{
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -