Thứ Bảy, 4 tháng 12, 2021

PHANSO1229 PASCAL

const fin='phanso1229.inp'; fon='phanso1229.out';
type ps=record
        t,m:int64;
        end;
var x:array[1..1000000] of ps;
    n:longint;

procedure doc;
var i:longint;
begin
        readln(n);
        for i:=1 to n do read(x[i].t);
        readln;
        for i:=1 to n do read(x[i].m);
end;

procedure swap(var x,y:ps);
var tam:ps;
begin
        tam:=x;
        x:=y;
        y:=tam;
end;

function ss( x,y:ps):longint;
VAR x1,y1:ps;
begin
        x1:=x;y1:=y;
        if x.m<0 then
        begin
                x1.m:=-x.m;
                x1.t:=-x.t;
        end;
        if y.m<0 then
        begin
                y1.m:=-y.m;
                y1.t:=-y.t;
        end;
        if (x1.t*y1.m)>(y1.t*x1.m) then exit (1);
        if (x1.t*y1.m)<(y1.t*x1.m) then exit(-1);
        if x.t<y.t then exit(-1);
        if x.t>y.t then exit(1);
        exit(0) ;
end;

procedure qs(l,r: longint);
var i,j: longint;
    g:ps;
begin
        g:= x[l+random(r-l)+1];
        i:=l; j:=r;
        repeat
                while ss(x[i],g)=-1 do inc(i);
                while ss(x[j],g)=1 do dec(j);
                if i<=j then
                        begin
                                swap(x[i],x[j]);
                                inc(i);
                                dec(j);
                        end;
        until i>j;
        if l<j then qs(l,j);
        if i<r then qs(i,r);
end;
procedure xuli;
var i:longint;
        s,k:qword;
begin
        if n=1 then
        begin
                writeln(x[i].t);
                write(x[i].m);
		exit;
        end;
        qs(1,n);
        for i:=1 to n do
                if x[i].t<>0 then write(x[i].t,' ');
        writeln;
        for i:=1 to n do
                if x[i].t<>0 then write(x[i].m,' ');
end;

begin
        assign(input,fin);reset(input);
        assign(output,fon);rewrite(output);
        doc;
        xuli;

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.