Cod sursa(job #1981405)

Utilizator Cosmin2004_InfoMoldoveanu Cosmin Cosmin2004_Info Data 15 mai 2017 16:56:11
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;
const double eps=1.e-14;
const double INF=2000000000;
struct POINT
{
    int x,y;
};
double dist(POINT a,POINT b)
{
    return sqrt((a.y-b.y)*(a.x-b.x)+(a.x-b.x)*(a.y-b.y));
}
double panta(POINT a,POINT b)
{
    if(a.x==b.x)
        return INF;
    else
        return (1.0*b.y-a.y)/(b.x-a.x);
}
vector<POINT> temp;
vector<double> v;

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int i,j,n,k=0,prev=-1,l=1;
    long long s=0;
    POINT p;
    scanf("%d", &n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d", &p.x,&p.y);
        temp.push_back(p);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            v.push_back(panta(temp[i],temp[j]));
        }
    }
    sort(v.begin(),v.end());  l=1;
    for(i=0;i<(int)v.size()-1;i++)
    {
       if(fabs(v[i]-v[i+1])<eps)l++;
       else
       {
           s=s+1LL*l*(l-1)/2;l=1;
       }
    }
    s+=1LL*l*(l-1)/2;
    printf("%lld\n", s);
    return 0;
}