Pagini recente » Cod sursa (job #2888307) | Cod sursa (job #2563499) | Cod sursa (job #2678134) | Cod sursa (job #2795369) | Cod sursa (job #2091445)
#include <iostream>
#include <fstream>
#include <algorithm>
#define Punct pair <int, int>
#define X first
#define Y second
#define Max 1005
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
Punct puncte[Max];
int n;
int suma;
int inf;
int counterSlope;
struct Slope
{
int numarator, numitor;
} Pante[5000000];
void citire()
{
in >> n;
for (int i = 0; i < n; i++)
{
in >> puncte[i].X >> puncte[i].Y;
}
}
int comparator(Slope a, Slope b)
{
return (a.numarator * b.numitor) < (a.numitor * b.numarator);
}
void SlopeConstruction()
{
for(int i = 0; i < n - 1; i++)
for(int j = i + 1; j < n; j++)
{
if(puncte[i].X - puncte[j].X == 0)
{
inf++;
continue;
}
if(puncte[i].X > puncte[j].X)
{
Pante[counterSlope].numarator = puncte[i].Y - puncte[j].Y;
Pante[counterSlope].numitor = puncte[i].X - puncte[j].X;
counterSlope++;
counterSlope++;
}
else
{
Pante[counterSlope].numarator = puncte[j].Y - puncte[i].Y;
Pante[counterSlope].numitor = puncte[j].X - puncte[i].X;
counterSlope++;
}
}
sort(Pante, Pante + counterSlope, comparator);
}
void NumarareTrapeze()
{
for(int i = 0; i < counterSlope - 1; i++)
for(int j = i + 1; j < counterSlope; j++)
{
if((Pante[i].numarator * Pante[j].numitor) == (Pante[i].numitor * Pante[j].numarator))
suma++;
}
suma += (inf * (inf - 1)) / 2;
}
int main()
{
citire();
SlopeConstruction();
NumarareTrapeze();
out << suma;
return 0;
}