Cod sursa(job #982697)

Utilizator Dddarius95Darius-Florentin Neatu Dddarius95 Data 9 august 2013 18:52:19
Problema Trapez Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <fstream>
#include <algorithm>
#include <math.h>
#include <vector>
#define Nmax 1099
#define x first
#define y second
#define Inf 2000000000
#define eps 0.00000000000001
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");

int n,Trapeze,Segmente;
pair<int,int> v[Nmax];
vector<long double> pante;

void ReadInput()
{
    f>>n;
    for(int i=1;i<=n;i++)f>>v[i].x>>v[i].y;
}

long double GetPanta(pair<int,int> a, pair<int,int> b)
{
    if(a.x==b.x) return Inf;
    return (long double)(b.y-a.y)/(long double)(b.x-a.x);
}

void FormeazaPantele()
{
    for(int i=1;i<=n-1;i++)
     for(int j=i+1;j<=n;j++)
        pante.push_back(GetPanta(v[i],v[j]));
}

void GetTrapeze()
{
    sort(pante.begin(),pante.end());
    Segmente=1;
    for(int i=0;i<(int)pante.size();i++)
        if(fabs(pante[i]-pante[i-1])<eps)Segmente++;
        else
        {
            Trapeze+=(Segmente*(Segmente-1)/2);
            Segmente=1;
        }
    g<<Trapeze<<'\n';
}
int main()
{
    ReadInput();
    FormeazaPantele();
    GetTrapeze();
    f.close();g.close();
    return 0;
}