Cod sursa(job #3278008)

Utilizator Cristian_NegoitaCristian Negoita Cristian_Negoita Data 18 februarie 2025 14:45:16
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
#define ld long double
#define int long long
const int NMAX = 1005;
struct point {ld x, y;} a[NMAX];
unordered_map<ld, int> unghiuri;

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

    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            if(a[j].x == a[i].x)
                continue;
            ld tg = (a[j].y - a[i].y) / (a[j].x - a[i].x);
            unghiuri[tg]++;
        }
    }

    int cnt = 0;
    for(auto i : unghiuri)
        cnt += i.second * (i.second - 1) / 2;
    fout << cnt;

    return 0;
}