Cod sursa(job #2479301)

Utilizator buhaidarius@gmail.comBuhai Darius [email protected] Data 23 octombrie 2019 17:45:48
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
//
//  main.cpp
//  Trapez
//
//  Created by Darius Buhai on 23/10/2019.
//  Copyright © 2019 Darius Buhai. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

#define INF 2.e+9

using namespace std;

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

struct point{
    double x, y;
};

vector<point> a;
vector<double> s;

double calculate_slope(point a, point b){
    if(a.x==b.x) return INF;
    return ((double)(b.y-a.y))/((double)(b.x-a.x));
}

int main() {
    int n, i ,j;
    point c;
    fin>>n;
    for(i=0;i<n;i++){
        fin>>c.x>>c.y;
        a.push_back(c);
    }
    for(i=0;i<a.size()-1;i++)
        for(j=i+1;j<a.size();j++){
            double m = calculate_slope(a[i], a[j]);
            s.push_back(m);
        }
    sort(s.begin(), s.end());
    int l = 1, tr = 0;
    for(i=1; i<s.size(); i++){
        if(s[i]==s[i-1])
            l++;
        else{
            tr += l*(l-1)/2;
            l = 1;
        }
    }
    tr += l*(l-1)/2;
    fout<<tr;
    return 0;
}