Cod sursa(job #1425394)

Utilizator czlateaZlatea Cezar czlatea Data 27 aprilie 2015 13:26:42
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const double INFI = 2e9;
const double eps = 1e-12;

struct PCT {
    int x,y;
    void cit () {
        int a,b;
        scanf("%d%d",&a,&b);
        x = a, y = b;
    }
} v[1001];

double pante[550000];

double CalculPanta (PCT a, PCT b) {

    int p,q;

    p=a.x-b.x;
    q=a.y-b.y;
    if (!p)
        return INFI + 1;
    return (double) q / p * 1.0;
}
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;++i)
        v[i].cit();
    int k=1,l=1;
    long long t=0;
    for (i=1;i<=n;++i)
        for (j=i+1;j<=n;++j)
            pante[k++] = CalculPanta(v[i],v[j]);
    sort (pante+1, pante+k);
    for (i=2;i<k;++i) {
        for (l=1;i<k&&fabs(pante[i]-pante[i+1])<eps;++i,++l);
        t += l * (l - 1) >> 1;
    }

    printf("%lld\n",t);
    return 0;
}