Cod sursa(job #3277962)

Utilizator Alex_BerbescuBerbescu Alexandru Alex_Berbescu Data 18 februarie 2025 12:06:29
Problema Trapez Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pqq priority_queue
#define mpp map<int, int>

using namespace std;
const int dim = 1e3 + 55;


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


map<int, vector<int> >hasu;

int ox, oy, n;

































struct el
{
    int x, y, idx;
    bool operator<(const el&ob) const
    {
        return x < ob.x;
    }




} v[dim];


int  sol;

map<long double, int>hasudoi;


int32_t main(int argc, char * argv[])
{

    fin >> n;
    for(int i = 1; i <= n; ++i)
    {
        fin >> v[i].x >> v[i].y;
        v[i].idx = i;
    }
    for(int i = 1; i < n; ++i) // retinem pantele oricaror 2 perechi de puncte
    {
        for(int j = i + 1; j <= n; ++j)
        {
            if(v[i].x == v[j].x)
            {
                oy++;
                continue;
            }

            int dify = (v[i].y - v[j].y);
            int difx = (v[i].x - v[j].x);
            hasudoi[(long double)dify / difx]++;
        }
    }
    sol = sol +  oy * (oy - 1) / 2;
    for(auto it = hasudoi.begin(); it!=hasudoi.end(); it++)
      sol = sol + it->second * (it->second - 1) / 2;

    fout << sol;

}