Mai intai trebuie sa te autentifici.
Cod sursa(job #1162210)
| Utilizator | Data | 31 martie 2014 18:25:03 | |
|---|---|---|---|
| Problema | Trapez | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.3 kb |
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
const int Nmax = 1000;
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( Point a, Point 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 += contor * ( contor - 1 ) / 2LL;
contor = 1;
}
}
sol += contor * ( contor - 1 ) / 2LL;
g << sol << "\n";
return 0;
}
