Cod sursa(job #1142874)

Utilizator multislashRobert Morosanu multislash Data 14 martie 2014 12:42:52
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1.e-14;
const double inf=2000000010;
struct POINT
{
    int x,y;
};
int n,i,j,c,nr,nr2;
double panta[1000002];
POINT p[1001];
double pant(POINT a,POINT b)
{
    if(a.x==b.x) return inf;
    else return ((double)a.y-b.y)/(a.x-b.x);
}
bool cmp(double a,double b)
{
    return a-b>eps;
}
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&p[i].x,&p[i].y);
        for(j=1;j<i;j++)
        {
            c++;
            panta[c]=pant(p[i],p[j]);
        }
    }
    sort(panta+1,panta+c+1,cmp);
    for(i=2;i<=c;i++)
    {
        if(fabs(panta[i]-panta[i-1])<eps)
        {
            nr2++;
        }
        else
        {
            nr=nr+nr2*(nr2+1)/2;
            nr2=0;
        }
    }
    nr=nr+nr2*(nr2+1)/2;
    printf("%d",nr);
}