Cod sursa(job #742158)

Utilizator visanrVisan Radu visanr Data 28 aprilie 2012 19:10:09
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define nmax 1 << 30

int x[1002], y[1002], length, solution, n;
double p[1000010];


double panta(int x1, int y1, int x2, int y2)
{
       return 1.0 * ( ( 1.0 * (y2 - y1)) / ( 1.0 * (x2 - x1) ));
}


int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%i", &n);
    int i, j;
    for(i = 1; i <= n; ++i)
    {
          scanf("%i %i", &x[i], &y[i]);
          for(j = i - 1; j >= 1 ; --j)
          {
                if( y[i] == y[j] ) p[length++] = 0;
                else
                if( x[i] == x[j] ) p[length++] = nmax;
                else p[length++] = panta( x[i], y[i], x[j], y[j]);
          }
    }
    sort( p , p + length);
    for(i = 0; i < length; )
    {
          int counter = 0, aux = i;
          while( p[i] == p[aux] && i < length)
          {
                 counter++;
                 i++;
          }
          solution += counter*(counter-1)/2;
    }
    printf("%i ", solution);
    return 0;
}