Cod sursa(job #1816396)

Utilizator VictoriaNevTascau Victoria VictoriaNev Data 26 noiembrie 2016 13:55:46
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1.e-14;
const double INF=1e9;
const int NMAX=1001;
/// joi 10:30
double slopes[1000001];

struct POINT
{
    double x, y;
} v[NMAX];


double slope(POINT p1, POINT p2)
{
    if(fabs(p1.x-p2.x)<eps)
        return INF;
    return (p2.y-p1.y)/(p2.x-p1.x);
}


int main()
{
    ifstream in("trapez.in");
    ofstream out("trapez.out");
    int n, nr=0, w;
    long long s=0;
    in>>n;
    for(int i=1; i<=n; i++)
        in>>v[i].x>>v[i].y;
    for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++)
            slopes[++nr]=slope(v[i], v[j]);
    sort(slopes+1, slopes+nr+1);
    //c de x luate cate 2
    w=1;
    for(int i=2; i<=nr; i++)
        if(slopes[i-1]==slopes[i])
            w++;
        else
        {
            s+=(w-1)*(w)/2;
            w=1;
        }
    out<<s<<'\n';
    return 0;
}