Cod sursa(job #3351654)

Utilizator c0drinn_Rau Codrin c0drinn_ Data 20 aprilie 2026 18:30:05
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <cmath>
#include <algorithm>

using namespace std;

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

struct POINT
{
    int x,y;
} v[1005];
const double INF=1.e9,eps=1.e-14;

double panta(POINT P1,POINT P2)
{
    if(fabs(P2.x-P1.x)<eps)
        return INF;
    else
        return (P2.y*1.0-P1.y)/(P2.x-P1.x);
}

double p[1000*999/2+5];
int main()
{
    int n,i,k=0,j,cnt=0,l;
    fin>>n;
    for(i=1; i<=n; i++)
        fin>>v[i].x>>v[i].y;
    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++)
            p[++k]=panta(v[i],v[j]);
    sort(p+1,p+k+1);
    l=1;
    for(i=1; i<=k; i++)
    {
        if(fabs(p[i]-p[i-1])<eps)
            l++;
        else
        {
            cnt=cnt+l*(l-1)/2;
            l=1;
        }
    }
    cnt=cnt+l*(l-1)/2;
    fout<<cnt;
    return 0;
}