Cod sursa(job #7443)

Utilizator CezarMocanCezar Mocan CezarMocan Data 21 ianuarie 2007 15:45:11
Problema Patrate 3 Scor 35
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.05 kb
type punct=record
                x,y:real;
           end;

var v:array[1..1000]of punct;
    n,i,j,k,nr:longint;
    aux,mij:punct;
    okp,okq:boolean;
    nr1,nr2:longint;

function dist(a,b:punct):real;
begin
dist:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
end;

function drept(a,b,c:punct):boolean;
//ac perp. pe bc
var a1,b1,a2,b2:real;
begin
a1:=c.y-a.y;
b1:=a.x-c.x;
a2:=c.y-b.y;
b2:=b.x-c.x;
if -a1*a2-b1*b2<0.00000001 then
        drept:=true
else
        drept:=false;
end;

begin
assign(input,'patrate3.in');reset(input);
assign(output,'patrate3.out');rewrite(output);
readln(n);
for i:=1 to n do
        readln(v[i].x,v[i].y);
for i:=1 to n-1 do
        for j:=i+1 to n do
                if (v[i].x>v[j].x)or((v[i].x=v[j].x)and(v[i].y>v[j].y)) then
                        begin
                        aux:=v[i];
                        v[i]:=v[j];
                        v[j]:=aux;
                        end;
for i:=1 to n-1 do
        for j:=i+1 to n do
                begin
                nr1:=0;
                nr2:=0;
                mij.x:=(v[i].x+v[j].x)/2;
                mij.y:=(v[i].y+v[j].y)/2;
                for k:=1 to n do
                        begin
                        if v[k].x>mij.x then
                                begin
                                if (abs(dist(v[k],v[i])-dist(v[k],v[j]))<0.000001)and
                                (drept(v[i],v[j],v[k])) then
                                        nr1:=1;
                                end
                        else
                                begin
                                if (abs(dist(v[k],v[i])-dist(v[k],v[j]))<0.000001)and
                                (drept(v[i],v[j],v[k])) then
                                        nr2:=1;
                                end;
                        end;
                if nr1<nr2 then
                        inc(nr,nr1)
                else
                        inc(nr,nr2);
                end;
writeln(nr div 2);
close(input);close(output);
end.