Cod sursa(job #2522332)

Utilizator CharacterMeCharacter Me CharacterMe Data 12 ianuarie 2020 13:12:46
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <bits/stdc++.h>
#define x first
#define y second
std::ifstream fin("trapez.in");
std::ofstream fout("trapez.out");
typedef long long ll;
ll n, sol, l, cnt=1;
std::pair<ll, ll> list[1005];
std::pair<double, double> lines[1000005];
double calc_m(std::pair<ll, ll> p1, std::pair<ll, ll> p2);
double calc_l(std::pair<ll, ll> p1, std::pair<ll, ll> p2);
int main()
{
    fin>>n;
    for(int i=1; i<=n; ++i){
        fin>>list[i].x>>list[i].y;
    }
    for(int i=1; i<n; ++i){
        for(int j=i+1; j<=n; ++j){
            lines[++l]={calc_m(list[i], list[j]), calc_l(list[i], list[j])};
        }
    }
    std::sort(lines+1, lines+l+1, [&](std::pair<double, double> p1, std::pair<double, double> p2){
            if(p1.x<p2.x) return true;
            else if(p1.x>p2.x) return false;
            else return p1.y<=p2.y;
        });
    for(int i=2; i<=l+1; ++i){
        if(i==l+1 || lines[i].x!=lines[i-1].x){
            sol=sol+(cnt-1)*cnt/2;
            cnt=0;
        }
        ++cnt;
    }
    fout<<sol;
    return 0;
}
double calc_m(std::pair<ll, ll> p1, std::pair<ll, ll> p2){
    return 1.0*(p2.y-p1.y)/(p2.x-p1.x);
}
double calc_l(std::pair<ll, ll> p1, std::pair<ll, ll> p2){
    return 1.0*sqrt((p2.y-p1.y)*(p2.y-p1.y)+(p2.x-p1.x)*(p2.x-p1.x));
}