Pagini recente » Cod sursa (job #2320792) | Cod sursa (job #2182325) | Cod sursa (job #2927675) | Cod sursa (job #880203) | Cod sursa (job #2091456)
#include <iostream>
#include <fstream>
#include <algorithm>
#define Punct pair <ll, ll>
#define X first
#define Y second
#define Max 1005
#define ll long long
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
Punct puncte[Max];
ll n;
ll suma;
ll inf;
ll counterSlope;
struct Slope
{
ll numarator, numitor;
} Pante[5000000];
void citire()
{
in >> n;
for (ll i = 0; i < n; i++)
{
in >> puncte[i].X >> puncte[i].Y;
}
}
ll comparator(Slope a, Slope b)
{
return (a.numarator * b.numitor) < (a.numitor * b.numarator);
}
void SlopeConstruction()
{
for(ll i = 0; i < n - 1; i++)
for(ll 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()
{
int lg = 1;
for(ll i = 1; i < counterSlope; i++)
if((Pante[i].numarator * Pante[i-1].numitor) == (Pante[i].numitor * Pante[i-1].numarator))
lg++;
else
{
suma += (lg * (lg - 1)) / 2, lg = 1;
}
suma += (lg * (lg - 1)) / 2;
suma += (inf * (inf - 1)) / 2;
}
int main()
{
citire();
SlopeConstruction();
NumarareTrapeze();
out << suma;
return 0;
}