贪心法,样例测试通过
program plan(input,output);
const maxn=1000;
var ans,i,j,n:longint;
left,right:array[1..maxn] of longint;
opt:array[1..maxn] of boolean;
procedure setio;
begin
assign(input,'plan.in');
assign(output,'plan.out');
reset(input);
rewrite(output);
end;
procedure swap(var a,b:longint);
var tmp:longint;
begin
tmp:=a;
a:=b;
b:=tmp;
end;
procedure init;
begin
readln(n);
for i:=1 to n do
begin
readln(left,right);
if left>right then
swap(left,right);
end;
fillchar(opt,sizeof(opt),true);
close(input);
end;
procedure solve;
procedure qsort;
procedure sort(l,r: longint);
var i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=right[(l+r) div 2];
repeat
while right<x do
inc(i);
while x<right[j] do
dec(j);
if not(i>j) then
begin
y:=right;
right:=right[j];
right[j]:=y;
y:=left;
left:=left[j];
left[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
sort(1,n);
end;
begin
qsort;
for i:=1 to n do
if opt then
for j:=i+1 to n do
if opt[j] and (left[j]<right) then
opt[j]:=false;
end;
procedure print;
begin
for i:=1 to n do
if opt then
inc(ans);
writeln(ans);
close(output);
end;
begin
setio;
init;
solve;
print;
end.