Cod sursa(job #2219612)

Utilizator dfettiDaniel Fetti dfetti Data 9 iulie 2018 13:47:51
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>
#define pair pair<int, int>
#define x first
#define y second
#define INF 0x3f3f3f3f
#define eps 0.00000000001
using namespace std;
 
ifstream fin ("trapez.in");
ofstream fout ("trapez.out");
 
int n, answ, aux;
vector <pair> v;
vector <double> P;
 
double Paralel(pair A, pair B);
 
int main()
{
    fin >> n;
    v.resize( n + 1);
    for ( int i = 1; i <= n; ++i )
    {
        fin >> v[i].x >> v[i].y;
        for ( int j = i - 1; j >= 1; --j )
            P.push_back( Paralel(v[i], v[j]) );
    }
    sort ( P.begin(), P.end() );
    int j;
    for ( int i = 0; i < P.size(); ++i )
    {
        j = i;
        if ( abs( P[i+1] - P[i] ) < eps ) aux++;
        else
        {
            answ += (aux*(aux+1)) / 2;
            aux = 0;
        }
    }
    answ += (aux*(aux+1)) / 2;
    fout << answ;
    return 0;
}
 
double Paralel(pair A, pair B)
{
    if (B.x == A.x) return INF;
    if (B.y == A.y) return 0;
    return 1. * (B.y - A.y) / (B.x - A.x);
}