Cod sursa(job #641132)

Utilizator gicu_01porcescu gicu gicu_01 Data 27 noiembrie 2011 13:31:44
Problema Triang Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 1.64 kb
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double polar(double,double);
void qs(int,int);
void sw(double *a,double *b);
void init();
int n;
double x[1501],y[1501],h[1501];

double polar(double x,double y)
{
    if (x>0)
      if (y>0) return atan(y/x); else return atan(y/x)+3.14*3;
    if (x<0) return 3.14+atan(y/x);else
    if (x==0)
        if (y>0) return 3.14/2; else
        if (y<0) return 3.14*3/2; else
        return 0;
}

void sw(double *a,double *b)
{
    double t=*a; *a=*b; *b=t;
}

void qs(int left,int right)
{
    int i,j; double p;
    i=left; j=right; p=h[(i+j)/2];
    while (i<j)
    {
        while (h[i]<p) i++;
        while (h[j]>p) j--;
        if (i<=j) {sw(&h[i],&h[j]); i++; j--;}
    }
    if (i<right) qs(i,right);
    if (j>left) qs(left,j);
}

void init()
{
    int i; double px,py;
    for (i=1; i<=n; i++) scanf("%f%f",&x[i],&y[i]);
    px=x[1]; py=y[1];
    for (i=2; i<=n; i++)
     if (py>y[i]) { py=y[i]; px=y[i];}
    for (i=1; i<=n; i++) h[i]=polar(x[i]-px,y[i]-py);
}
double dist(double x1,double y1,double x2,double y2)
{
    return sqrt(pow(abs(x1-x2),2)+pow(abs(y1-y2),2));
}

int main()
{
    int k,i,j,c; double a,b,d;
    freopen("triang.in","r",stdin);
    freopen("triang.out","w",stdout);
    scanf("%i",&n);
    init();
    qs(1,n);
    k=0;
    for (i=1; i<=n-2; i++)
       for (j=i+1; j<=n-1; j++)
          for (c=j+1; c<=n; c++)
           {
               a=dist(x[i],y[i],x[j],y[j]); b=dist(x[i],y[i],x[c],y[c]); d=dist(x[c],y[c],x[j],y[j]);
               if (a==b && a==d && d==b) k++;
           }
    printf("%i",k);
    return 0;
}