比赛 NOIP2008集训模拟4 评测结果 AWWWWWWWWW
题目名称 彩色穿孔卡片 最终得分 10
用户昵称 chengyang 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-13 08:51:06
显示代码纯文本
program punch;
var
  a:array[1..110000]of longint;
  i,x,y,n,h:longint;
procedure go(x,y:longint);
var
  i,j,k:longint;
Begin
  i:=h; j:=h;
  while (x<a[i])and(i>0) do i:=i-1;
  i:=i+1;
  if a[i-1]<>x then begin
    if i<=h then  for k:=h downto i do a[i+1]:=a[i];
    a[i]:=x; h:=h+1;
  end;
  while (y<a[j])and(j>0) do j:=j-1;
  j:=j+1;
  if a[j-1]<>y then begin
     if j<=h  then for k:=h downto j do a[j+1]:=a[j];
     a[j]:=y; h:=h+1;
  end;
End;
Begin
  assign(input,'punch.in');
  assign(output,'punch.out');
  reset(input); rewrite(output);
  readln(n); h:=2;
  readln(x,y);
  a[1]:=x;  a[2]:=y;
  for i:=1 to n-1 do  begin
    readln(x,y);
    go(x,y);
  end;
  writeln((h/2-1):0:0);
  close(input); close(output);
End.