Pagini recente » Cod sursa (job #1602628) | Cod sursa (job #1162205)
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
const int Nmax = 1000;
const double EPS = 1e-9;
typedef long long ll;
#define x first
#define y second
#define Point pair<ll,ll>
bool eq( Point a, Point b )
{
return ( a.x * b.y == b.x * a.y );
}
bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
if (a.x * b.y == b.x * a.y) return 0;
bool r = (a.x * b.y < b.x * a.y);
if (b.y < 0) r = !r;
if (a.y < 0) r = !r;
return r;
}
Point slopes[Nmax * Nmax];
Point P[Nmax + 1];
int N;
int main()
{
ifstream f("trapez.in");
ofstream g("trapez.out");
f >> N;
for ( int i = 1; i <= N; ++i )
f >> P[i].x >> P[i].y;
int M = 0;
for ( int i = 1; i < N; ++i )
for ( int j = i + 1; j <= N; ++j )
slopes[ ++M ] = Point( P[i].x - P[j].x, P[i].y - P[j].y );
sort( slopes + 1, slopes + 1 + M, cmp );
ll contor = 1;
ll sol = 0;
for ( int i = 2; i <= M; ++i )
{
if ( eq( slopes[i - 1], slopes[i] ) )
contor++;
else
{
sol += 1LL * contor * ( contor - 1 ) / 2LL;
contor = 1;
}
}
sol += 1LL * contor * ( contor - 1 ) / 2LL;
g << sol << "\n";
return 0;
}