Cod sursa(job #427507)

Utilizator gabipurcaruGabi Purcaru gabipurcaru Data 27 martie 2010 22:09:36
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;

ifstream in("trapez.in");
ofstream out("trapez.out");

struct PUNCT
{
    int x,y;
};

inline int fact(int n)
{
    if(n==0)
        return 0;
    int ret=1, i;
    for(i=2; i<=n; i++)
        ret*=i;
    return ret;
}

PUNCT x[1010];
int i,j,n,s,nr;
double p[3050], *q,k;

bool cmp(double x, double y)
{
    return fabs(x-y) <= 0.0001;
}

int main()
{
    in>>n;
    for(i=1; i<=n; i++)
        in>>x[i].x>>x[i].y;

    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++)
        {
            if(x[i].x - x[i].y == 0 && x[j].x - x[j].y == 0)
                p[++nr] = 32000;
            if(x[i].x == x[j].x || x[i].y == x[j].y)
                continue;
            p[++nr] = (x[i].y-x[j].y)/(x[i].x-x[j].x);
        }
    sort(p+1,p+nr+1);

    nr = 1;k=p[1];
    for(i=2; i<=n; i++)
    {
        if(p[i] != k)
            s+=(nr-1)*nr/2, nr=0, k=p[i];
        nr++;
    }
    
    out<<s;
    
    return 0;
}