Pagini recente » Cod sursa (job #1327495) | Cod sursa (job #2796471) | Cod sursa (job #721338) | Cod sursa (job #2109887) | Cod sursa (job #1162201)
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
const int Nmax = 1000;
const double EPS = 1e-9;
#define x first
#define y second
typedef long long ll;
struct Point
{
int x, y;
friend istream& operator >> ( istream &f, Point &P )
{
f >> P.x >> P.y;
return f;
}
};
bool eq( const pair<int,int> &a, const pair<int,int> &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;
}
pair<int,int> 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];
int M = 0;
for ( int i = 1; i < N; ++i )
for ( int j = i + 1; j <= N; ++j )
slopes[ ++M ] = pair<int,int>( 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;
}