Cod sursa(job #1142866)

Utilizator raddudjPogonariu Radu raddudj Data 14 martie 2014 12:30:57
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
const double INF=(1LL<<31)-1;
const double eps=1.e-14;
using namespace std;
struct POINT
{
    double x,y;
};
vector <double> pan;
POINT a[1010];
inline bool vertical(POINT A,POINT B)
{
    return A.x==B.x;
}
inline void panta(POINT A,POINT B)
{
    if(vertical(A,B))
    {
        pan.push_back(INF);
        return;
    }
    pan.push_back((B.y-A.y)/(B.x-A.x));
}
int main()
{
    int n,i,j,sum=0,nr=0;
    double last,x,y;
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%lf%lf",&x,&y);
        a[i].x=x;
        a[i].y=y;
    }
    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++)
            panta(a[i],a[j]);
    sort(pan.begin(),pan.end());
    last=pan[0];
    nr=1;
    for(i=1; i<=pan.size()-1; i++)
        if(last==pan[i])
            nr++;
        else
        {
            if(nr>1)
                sum+=(nr*(nr-1)/2);
            nr=1;
            last=pan[i];
        }
        printf("%d\n",sum);
    return 0;
}