# Cod sursa(job #20581)

Utilizator Data 21 februarie 2007 19:35:57 Numarare triunghiuri 0 fpc done Arhiva de probleme 1.38 kb
``````Var
db:longint;
i,j,a,b,c,k:word;
n:word;
et,v:array[-1..801] of 0..30000;
f:text;
kesz,jo:boolean;
Function szetvalogat(e,u:word):word;
var seged:integer;
begin
seged:=et[e];
while e<u do begin
while (e<u) and (et[u]>=seged) do
dec(u);
if e<u then begin
et[e]:=et[u];
inc(e);
while (e<u) and (et[e]<seged) do
inc(e);
et[u]:=et[e];
dec(u);
end;
end;
et[e]:=seged;
szetvalogat:=e;
end;
procedure gyors(ah,fh:integer);
var k:integer;
begin
if ah<fh then begin
k:=szetvalogat(ah,fh);
gyors(ah,k-1);
gyors(k+1,fh);
end;
end;
{function binker(e,u:integer):integer;
var k:integer;
begin
if e>u then binker:=0
else begin
k:=(e+u) div 2;
if (et[k]<=a+b) and then binker:=k
else
if mit<et[k] then binker:=binker(e,k-1,mit)
else binker:=binker(k+1,u,mit);
end;
end;               }

begin
Assign(f,'nrtri.in');
reset(f);
for i:=1 to n do
close(f);
gyors(1,n);
i:=n;
k:=n;
while k>1 do begin
i:=k;
while i>3 do begin
jo:=true;
a:=et[k];
b:=et[i];
j:=i-1;
while (jo) and (j>0) do begin
c:=et[j];
if (c>a+b) or (a>c+b) or (b>c+a) then jo:=false;
j:=j-1;
end;
db:=db+i-j-2;
i:=i-1;
end;
k:=k-1;
end;

writeln(db);
assign(f,'nrtri.out');
rewrite(f);
end.``````