Cod sursa(job #1710374)

Utilizator radu.millio15Radu Millio radu.millio15 Data 28 mai 2016 21:03:01
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <algorithm>
#include <stdio.h>
#include <cmath>

using namespace std;
const double INF=1.e9;
const double eps=1.e-14;
struct POINT
{
    int x, y;
};
POINT v[1005];
double p[500000];
double panta (POINT P1, POINT P2)
{
    if(fabs(P1.x-P2.x)<eps)
        return INF;
    else
        return 1.0*(P2.y-P1.y)/(P2.x-P1.x);
}

bool cmp(double a, double b)
{
    return(a-b<=-eps);
}

int main()
{
    int n,i,cnt,lg,k,j;
    double pred;
    FILE *fin, *fout;
    fin=fopen("trapez.in", "r");
    fout=fopen("trapez.out", "w");
    fscanf(fin, "%d", &n);
    for(i=1; i<=n; i++)
        fscanf(fin, "%d%d", &v[i].x, &v[i].y);
    k=0;
    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++)
            p[++k]=panta(v[i], v[j]);
    sort(p+1, p+k+1, cmp);
    pred=p[i];
    lg=1;
    cnt=0;
    for(i=2; i<=k; i++)
    {
        if(fabs(p[i]-pred)<eps)
            lg++;
        else
        {
            cnt+=lg*(lg-1)/2;
            lg=1;
            pred=p[i];
        }
    }
    fprintf(fout, "%d", cnt);
    return 0;
}