Cod sursa(job #3351646)

Utilizator CiuntuTiberiuCiuntu Tiberiu CiuntuTiberiu Data 20 aprilie 2026 18:18:58
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
struct POINT{
    double x,y;
}v[1005];
const double INF=1.e9,eps=1.e-14;

double dist(POINT P1,POINT P2)
{
    return sqrt((P2.x-P1.x)*(P2.x-P1.x)+(P2.y-P1.y)*(P2.y-P1.y));
}

bool same_point(POINT P1,POINT P2)
{
    if(fabs(P1.x-P2.x)<eps && fabs(P1.y-P2.y)<eps)
        return 1;
    return 0;
}

POINT median(POINT P1,POINT P2)
{
    POINT M;
    M.x=(P1.x+P2.x)/2;
    M.y=(P1.y+P2.y)/2;
    return M;
}

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

double p[1000*999/2+5];
int main()
{
    int n,i,k=0,j,cnt=0,l,ll;
    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;
    ll=2;
    while(l<k && ll<=k)
    {
        if(fabs(p[l]-p[ll])<eps)
        {
            cnt=cnt+(ll-l)*(ll-l-1)/2;
            l=ll;
            ll=l+1;
        }
        else
            ll++;
    }
    fout<<cnt;
    return 0;
}