Cod sursa(job #268654)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 1 martie 2009 16:50:56
Problema Trapez Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.62 kb
program alex;
var f:text;
    x,y:array[1..1005]of longint;
    s,s1:array[1..1000005]of longint;
    a,b,i,n,k,z,w,d,c,poz,q,c1,r:longint;
    t,u,nr:int64;
    e:boolean;
begin
assign(f,'trapez.in');reset(f);
readln(f,n);
for i:=1 to n do
    readln(f,x[i],y[i]);
close(f);
nr:=0;
k:=0;
d:=0;q:=0;
for a:=1 to n-1 do
    for b:=a+1 to n do
        begin
        e:=false;
        if y[b]-y[a]=0 then begin
                            e:=true;
                            d:=d+1;
                            end;
        if x[b]-x[a]=0 then begin
                            q:=q+1;
                            e:=true;
                            end;

        if e=false then begin
                        k:=k+1;
                        s[k]:=(y[b]-y[a]);
                        s1[k]:=(x[b]-x[a]);
                        c:=abs(s[k]);
                        c1:=abs(s1[k]);
                        r:=c mod c1;
                        while r<>0 do
                              begin
                              c:=c1;
                              c1:=r;
                              r:=c mod c1;
                              end;
                        s[k]:=s[k] div c1;
                        s1[k]:=s1[k] div c1;
                        end;
        end;
nr:=nr+(d*(d-1)) div 2;
nr:=nr+(q*(q-1)) div 2;
d:=0;
c:=k-1;
e:=false;
while e=false do
      begin
      e:=true;
      for i:=1 to c do
          begin
          t:=(s[i]*s1[i+1]-s1[i]*s[i+1]);
          u:=(s1[i]*s1[i+1]);
          if((t>0)and(u>0))or((t<0)and(u<0))then begin
                                                                e:=false;
                                                                z:=s[i];
                                                                s[i]:=s[i+1];
                                                                s[i+1]:=z;
                                                                z:=s1[i];
                                                                s1[i]:=s1[i+1];
                                                                s1[i+1]:=z;
                                                                w:=i;
                                                                end;
            end;
      c:=w;
      end;
poz:=1;
for i:=1 to k-1 do
    begin
    t:=s[i]*s1[i+1];
    u:=s1[i]*s[i+1];
    if t<>u then begin
                 d:=i-poz+1;
                 poz:=i+1;
                 nr:=nr+(d*(d-1))div 2;
                 end;
    end;
d:=k-poz+1;
nr:=nr+(d*(d-1))div 2;
assign(f,'trapez.out');rewrite(f);
writeln(f,nr);
close(f);
end.