Cod sursa(job #2606235)

Utilizator star1star21Stefan Birca star1star21 Data 27 aprilie 2020 12:47:27
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
const double INF=2.0e+9;
const double eps=1.e-14;
struct POINT
{
    int x,y;
};
double panta(POINT p1, POINT p2)
{
    if(p1.x==p2.x)
    {
        return INF;
    }
        return (1.0*p2.y-p1.y)/(1.0*p2.x-p1.x);
}
POINT v[1005];
double p[500000];
int main()
{short int n,i,j;
int cnt=0,r=0,x,s=1;
fin>>n;
for(i=1;i<=n;i++)
{
    fin>>v[i].x>>v[i].y;
}
for(i=1;i<=n-1;i++)
{
    for(j=i+1;j<=n;j++)
    {
        cnt++;
        p[cnt]=panta(v[i],v[j]);
    }
}
sort(p+1,p+cnt+1);
for(x=1;x<=cnt-1;x++)
{
    if(fabs(p[x]-p[x+1])<eps)
    {
        s++;
    }
    else
    {
        r+=s*(s-1)/2;
        s=1;
    }
}
fout<<r;
    return 0;
}