Cod sursa(job #2047711)

Utilizator sebi212Sebi nechita sebi212 Data 25 octombrie 2017 10:17:54
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const double eps=1.e-14;
const double INF=2.e9;
struct POINT
{
    double x,y;
};
bool vertical(POINT P1,POINT P2)
{
    return fabs(P1.x-P2.x)<eps;
}
double panta(POINT P1,POINT P2)
{
    if(vertical(P1,P2))
        return INF;
    return (P2.y-P1.y)/(P2.x-P1.x);
}
vector<POINT> points;
vector<double> p;
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,i,j;
    scanf("%d",&n);
    POINT P;
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf",&P.x,&P.y);
        points.push_back(P);
    }
    double ok;
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
    {
        ok=panta(points[i],points[j]);
        p.push_back(ok);
    }
    sort(p.begin(),p.end());
    int nr=0,nr1=1;
    for(i=0;i<p.size()-1;i++)
    {
        if(fabs(p[i]-p[i+1])<eps)
            nr1++;
         else
         {
            nr=nr+(nr1*(nr1-1))/2;
            nr1=1;
         }
    }
    nr=nr+(nr1*(nr1-1)/2);
    printf("%d",nr);

}