Pagini recente » Cod sursa (job #1961332) | Cod sursa (job #453372) | Cod sursa (job #2288745) | Cod sursa (job #12436) | Cod sursa (job #16531)
Cod sursa(job #16531)
const aa = (sqrt(5)-1)/2;
nmax = 1500;
hashmax = 100000;
type pc = record
x,y:real;
end;
var a :array[1..nmax] of pc;
pcc : array[0..hashmax] of pc;
uz : array[0..hashmax] of boolean;
n:integer;
function hash(x:real):longint;
begin
hash:= abs(trunc(hashmax * ( frac(x*aa) )));
end;
function egal(x,y:real):boolean;
begin
if abs(x-y) < 0.0001 then egal:=true
else egal:=false;
end;
procedure inserthash(z:pc);
var poz,i:longint;
begin
poz:=hash(z.x+z.y);
while uz[poz] do
begin
inc(poz);
if poz >hashmax then poz:=0;
end;
pcc[poz]:=z;
uz[poz]:=true;
end;
function cautahash(z:pc):boolean;
var poz:longint;
begin
cautahash:=false;
poz:=hash(z.x+z.y);
while (uz[poz]) do
begin
if egal(pcc[poz].x,z.x) and egal(pcc[poz].y,z.y) then
begin
cautahash:=true;
break;
end;
inc(poZ);
if poz > hashmax then poz:=0;
end;
end;
procedure citire;
var i:integer;
begin
assign(input,'triang.in'); reset(input);
readln(n);
for i:=1 to n do
begin
readln(a[i].x,a[i].y);
inserthash(a[i]);
end;
closE(input);
end;
function panta(p1,p2:pc):double;
begin
panta:=- (p1.x-p2.x) / (p1.y-p2.y);
end;
function lungime(p1,p2:pc):double;
begin
lungime:=sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ) * sqrt(3) / 2;
end;
procedure calc;
var i,j:integer;
rez:longint;
ldd,mdd,xm,ym,xx1,xx2,yy1,yy2,r:real;
p1,p2:pc;
begin
rez:=0;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if abs(a[i].y-a[j].y) > 0.0001 then
begin
ldd:=lungime(a[i],a[j]);
mdd:=panta(a[i],a[j]);
xm:=(a[i].x+a[j].x) / 2;
ym:=(a[i].y+a[j].y) / 2;
xx1 := xm + sqrt( sqr(ldd) / (1+ sqr(mdd)));
xx2 := xm - sqrt( sqr(ldd) / (1+ sqr(mdd)));
r:=mdd*(xx1-xm);
//writeln(r:5:10);
//writeln(ym:5:10);
//writeln(r+ym:5:10);
yy1:= ym + r;
yy2:= ym + mdd*(xx2-xm);
end
else
begin
xm:=(a[i].x+a[j].x) /2 ;
ldd:=lungime(a[i],a[j]);
xx1:=xm; xx2:=xm;
yy1:=a[i].y+ldd;
yy2:=a[i].y-ldd;
end;
p1.x:=xx1; p1.y:=yy1;
p2.x:=xx2; p2.y:=yy2;
if cautahash(p1) then inc(rez);
if cautahash(p2) then inc(rez);
end;
assign(output,'triang.out'); rewrite(output);
writeln(rez div 3);
close(output);
end;
begin
citire;
calc;
end.