Pagini recente » Cod sursa (job #1854255) | Cod sursa (job #1798053) | Cod sursa (job #1250812) | Cod sursa (job #1507676) | Cod sursa (job #1775161)
//
// 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;
}