Cod sursa(job #1388532)

Utilizator alexmarMarinescu Alexandru alexmar Data 15 martie 2015 15:47:28
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
#include<vector>
#define NMAX 1001
#include<algorithm>
using namespace std;

ifstream fin("trapez.in");
ofstream fout("trapez.out");

struct punct {
    int x, y;
};



int n;
punct p[NMAX];
vector <double> v;

int main(){
    fin>>n;
    for (int i=1;i<=n;i++)fin>>p[i].x>>p[i].y;

    double panta;

    for (int i=2;i<=n;i++)
        for (int j=1;j<i;j++) {
            panta=(p[i].y-p[j].y)*1.0/(p[i].x-p[j].x);
            v.push_back(panta);
        }
    sort(v.begin(),v.end());
    int nr=1,sol=0;
    for (int i=1;i<v.size();i++)
        if (v[i]==v[i-1])nr++;
        else{
            sol+=nr*(nr-1)/2;
            nr=1;
        }
    sol+=nr*(nr-1)/2;
    fout<<sol;
    return 0;
}