Cod sursa(job #2522315)

Utilizator CharacterMeCharacter Me CharacterMe Data 12 ianuarie 2020 12:37:10
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.74 kb
#include <bits/stdc++.h>
#define x first
#define y second
#define inf 1.0/0.0
std::ifstream fin("trapez.in");
std::ofstream fout("trapez.out");
typedef long long ll;
ll n, sol, l, last, cnt, m_cnt;
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;
        });
    last=1; cnt=1;
    for(int i=2; i<=l+1; ++i){
        if(i!=l+1 && lines[i].x==lines[i-1].x) ++cnt;
        else{
            /*double d=lines[i].y;
            lines[i].y=lines[i-1].y+1.0; m_cnt=1;
            --cnt;
            for(int j=last+1; j<=i; ++j){
                if(lines[j].y==lines[j-1].y) ++m_cnt;
                else {
                    sol=sol+m_cnt*(m_cnt-1+cnt);
                    m_cnt=1;
                }
                --cnt;
            }
            lines[i].y=d; last=i; cnt=1;*/
            sol=sol+(cnt-1)*cnt/2;
            cnt=1;
        }
    }
    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));
}