Cod sursa(job #3155841)

Utilizator PsyDuck1914Feraru Rares-Serban PsyDuck1914 Data 9 octombrie 2023 20:48:57
Problema Trapez Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f ("trapez.in");
ofstream g ("trapez.out");

const int NMAX = 1e3;
map<pair<int, int>, int> cmap;
vector<pair<int, int>> v;

int cmmdc(int a, int b){
    while(b){
        int r = a%b;
        a = b;
        b = r;
    }
    return a;
}

void prelucrare(int i, int j){
    
    int x1 = v[i].first;
    int x2 = v[j].first;
    int y1 = v[i].second;
    int y2 = v[j].second;
    
    int trim = cmmdc(x2-x1, y2-y1);
    cmap[{(y2-y1)/trim, (x2-x1)/trim}] ++;
}

int main()
{
    int n;
    f >> n;
    f.tie(NULL);
    
    for(int i=1; i<=n; i++){
        int x, y;
        f >> x >> y;
        v.push_back({x, y});
    }
    
    sort(v.begin(), v.end());
   
    
    for(int i=0; i<n-1; i++)
        for(int j=i+1; j<n; j++){
            prelucrare(i, j);
        }
    
    int cnt = 0;
    for(auto i : cmap){
        int val = i.second;
        cnt += val*(val-1)/2;
    }
    
    g << cnt;
     
    
    return 0;
}