Cod sursa(job #1925180)

Utilizator isav_costinVlad Costin Andrei isav_costin Data 12 martie 2017 15:58:58
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const double eps = 1.e-14;

struct Pct
{
    int x, y;
};

Pct v[1001];

struct Dr
{
    int a, b, c;
};

Dr getDr( Pct p1, Pct p2 )
{
    Dr d;

    d.a=p2.y-p1.y;
    d.b=p1.x-p2.x;
    d.c=p1.y*p2.x-p1.x*p2.y;

    return d;
}

double getPanta( Dr d )
{
    return (double) -d.a/d.b;
}

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

vector <double> panta;

int main()
{
    freopen( "trapez.in", "r", stdin );
    freopen( "trapez.out", "w", stdout );

    int n, trp=0, k=1, i, j;

    scanf( "%d", &n );

    for( i=1;i<=n;i++ )
        scanf( "%d%d", &v[i].x, &v[i].y );

    for( i=1;i<n;i++ )
        for( j=i+1;j<=n;j++ )
        {
            Dr d=getDr(v[i],v[j]);
            panta.push_back(getPanta(d));
        }

    sort(panta.begin(),panta.end(),cmp);

    for( i=1;i<=panta.size();i++ )
        if( panta[i]-panta[i-1]<=eps )
            k++;
        else
        {
            trp+=k*(k-1)/2;
            k=1;
        }

    printf( "%d", trp );

    return 0;
}