Thứ Ba, 3 tháng 5, 2022

SETS PASCAL

type pt=record
        t,p:longint;
end;
var y,x,n,d:int64;
i,j:longint;
a:array[0..100000] of pt;
b:array[0..100000] of int64;
function sosanh(x,y:pt):boolean;
begin
        if x.p<y.p then exit(true);
        if x.p>y.p then exit(false);
        if x.t>y.t then exit(true);
        if x.t<y.t then exit(false);
        exit(false);
end;
procedure quicksort(l,h:longint);
var tmp,t:pt;
begin
        i:=l;
        j:=h;
        t:=a[(l+h) div 2];
        repeat
                while sosanh(a[i],t)=true do inc(i);
                while sosanh(t,a[j])=true do dec(j);
                if i<=j then
                begin
                        tmp:=a[i];
                        a[i]:=a[j];
                        a[j]:=tmp;
                        inc(i);
                        dec(j);
                end;
        until i>j;
        if l<j then quicksort(l,j);
        if i<h then quicksort(i,h);
end;
procedure giai;
begin
        readln(n);
        for i:=1 to n do
        read(a[i].t,a[i].p);
        quicksort(1,n);
        d:=0;
        inc(d);b[d]:=a[1].p-1;
        inc(d);b[d]:=a[1].p;
        for i:=2 to n do
        if a[i].t>b[d] then
        begin
                inc(d);b[d]:=a[i].p-1;
                inc(d);b[d]:=a[i].p;
        end else
        if a[i].t>b[d-1] then
        begin
                inc(d);
                b[d]:=a[i].p;
        end;
        writeln(d);
end;
begin

        assign(input,'sets.inp');
        reset(input);
        assign(output,'sets.out');
        rewrite(output);
        giai;
        close(input);
        close(output);

end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.