Cod sursa(job #1775161)

Utilizator ducu34Albastroiu Radu Gabriel ducu34 Data 9 octombrie 2016 22:27:23
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
//
//  main.cpp
//  Trapez
//
//  Created by Albastroiu Radu on 10/9/16.
//  Copyright © 2016 Albastroiu Radu. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <unordered_map>
#include <vector>

using namespace std;

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

long long i, j, n, nr, suma;
double h, m, x, y, dif;

struct punct
{
    double x,y;
}element;

vector<punct> puncte;
vector<double> panta;

int main()
{
    
    fin >> n;
    for(i=1;i<=n;i++)
    {
        fin >> x >> y;
        
        element.x = x;
        element.y = y;
        puncte.push_back(element);
    }
    
    for(i = 0; i < puncte.size(); i++)
    {
        for(j = i+1; j < puncte.size(); j++)
        {
            m = (puncte[j].y - puncte[i].y) / (puncte[j].x - puncte[i].x);
            panta.push_back(m);
        }
    }
    
    sort(panta.begin(), panta.end());
    
    dif = 0.000001; // 10^(-4)
    
    nr = 1;
    for(i = 1; i < panta.size(); i++)
    {
        if(panta[i] == panta[i-1])
        {
            nr++;
        }
        else
        {
            suma += (nr * (nr-1))/2;
            nr = 1;
        }
    }
    
    fout << suma;
    
    return 0;
}