Pagini recente » Cod sursa (job #2312129) | Cod sursa (job #2623337) | Cod sursa (job #3156536) | Cod sursa (job #2625339) | Cod sursa (job #134697)
Cod sursa(job #134697)
type point=record
x,y:longint;
end;
var a,b,c:array[0..1000001] of point;
f,g:text;
q,w,e:qword;
aux,j,nr,nr2,i,n,numar:longint;
ok1,ok2:boolean;
procedure inter(st,mij,dr:longint);
var i,j,k,t:longint;
begin
i:=st;
j:=mij+1;
k:=st;
for t:=st to dr do
b[t]:=a[t];
while (i<=mij) and (j<=dr) do begin
q:=abs(b[i].x);
e:=abs(b[j].y);
q:=q*e;
w:=abs(b[i].y);
e:=abs(b[j].x);
w:=w*e;
ok1:=not((b[i].x<0) xor (b[j].y<0));
ok2:=not((b[i].y<0) xor (b[j].x<0));
if ((q>w) and (ok1) and (ok2)) or ((ok1=false) and (ok2=true)) or ((q<w) and (ok2=false) and (ok1=false)) then begin
a[k]:=b[j];
inc(k);
inc(j);
end
else begin
a[k]:=b[i];
inc(k);
inc(i);
end;
end;
for t:=i to mij do begin
a[k]:=b[t];
inc(k);
end;
for t:=j to dr do begin
a[k]:=b[t];
inc(k);
end;
end;
procedure mergesort(st,dr:longint);
var mij:longint;
begin
if st<dr then begin
mij:=(st+dr) div 2;
mergesort(st,mij);
mergesort(mij+1,dr);
inter(st,mij,dr);
end;
end;
procedure comb(x:longint);
var e:longint;
begin
e:=(x-1)*x div 2;
inc(nr2,e);
end;
begin
assign(f,'trapez.in'); reset(f);
assign(g,'trapez.out'); rewrite(g);
read(f,n);
for i:=1 to n do
read(f,c[i].x,c[i].y);
for i:=1 to n-1 do
for j:=i+1 to n do
if (c[i].x>c[j].x) or ((c[i].x=c[j].x) and (c[i].y>c[j].y)) then begin
aux:=c[i].x;
c[i].x:=c[j].x;
c[j].x:=aux;
aux:=c[i].y;
c[i].y:=c[j].y;
c[j].y:=aux;
end;
for i:=1 to n-1 do
for j:=i+1 to n do begin
inc(numar);
a[numar].x:=c[j].x-c[i].x;
a[numar].y:=c[j].y-c[i].y;
end;
n:=numar;
mergesort(1,n);
a[0]:=a[1];
i:=1;
while i<=n do begin
nr:=1;
ok1:=(a[i].x<0) xor (a[i+1].y<0);
ok2:=(a[i].y<0) xor (a[i+1].x<0);
q:=abs(a[i].x);
e:=abs(a[i+1].y);
q:=q*e;
w:=abs(a[i].y);
e:=abs(a[i+1].x);
w:=w*e;
while (q=w) and (ok1=ok2) and (i+1<=n) do begin
inc(nr);
inc(i);
q:=abs(a[i].x);
e:=abs(a[i+1].y);
q:=q*e;
w:=abs(a[i].y);
e:=abs(a[i+1].x);
w:=w*e;
ok1:=not((a[i].x<0) xor (a[i+1].y<0));
ok2:=not((a[i].y<0) xor (a[i+1].x<0));
end;
comb(nr);
inc(i);
end;
writeln(g,nr2);
close(g); close(f);
end.