Cod sursa(job #1670631)

Utilizator emanuel_rRamneantu Emanuel emanuel_r Data 31 martie 2016 21:40:16
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include<iostream>
#include<fstream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<bitset>
#include<algorithm>

using namespace std;

ifstream f("trapez.in");
ofstream g("trapez.out");

pair <double, double> P[1005];
vector <double> D;
double const tol = 1e-14;
int n;
long long sol;

void Read()
{
    f>>n;
    for(int i=1; i<=n; i++){
        f>>P[i].first>>P[i].second;
    }
}

void Solve()
{
    int i, j, oy = 0, card;
    double m, el;

    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++){
            if(P[i].first - P[j].first == 0){
                oy++;
                continue;
            }
            m = (P[i].second - P[j].second) / (P[i].first - P[j].first);
            D.push_back(m);
        }
    sort(D.begin(), D.end());
    for(i=0; i<D.size(); i++){
        card = 1;
        for(j=i+1; j<D.size() && abs(D[j] - D[i]) < tol; j++)
            card++;
        sol += 1LL*card*(card-1)/2;
        i = j-1;
    }
    sol += 1LL*(oy-1)*oy/2;
    g<<sol<<"\n";
}

int main()
{
    Read();
    Solve();
    return 0;
}