Pagini recente » Cod sursa (job #450121) | Cod sursa (job #1155454) | Cod sursa (job #2378982) | Cod sursa (job #2464357) | Cod sursa (job #2876227)
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream cin ( "trapez.in" );
ofstream cout ( "trapez.out" );
#define NMAX 1001
#define INF (1LL<<32)
#define EPS 0.00000000000001
struct POINT {
long long int x, y;
};
long double getpanta( const POINT& a, const POINT& b ) {
if ( a.x == b.x )
return INF;
return ( (long double)b.y - a.y ) / ( (long double)b.x - a.x );
}
struct DREAPTA {
long double panta;
bool operator < ( const DREAPTA& other ) const {
return panta < other.panta;
}
};
vector<DREAPTA> drepte;
POINT v[NMAX];
int main() {
long long n, i, j, ans;
long double x;
cin >> n;
for ( i = 0; i < n; i++ ) {
cin >> v[i].x >> v[i].y;
}
for ( i = 1; i < n; i++ ) {
for ( j = 0; j < i; j++ ) {
x = getpanta( v[j], v[i] );
drepte.push_back({x});
}
}
sort ( drepte.begin(), drepte.end() );
ans = 0;
for ( i = 1; i < drepte.size(); i++ ) {
j = i;
while ( j < drepte.size() && drepte[i].panta == drepte[j].panta )
j++;
ans += ( j - i ) * ( j - i - 1 ) / 2;
}
cout << ans;
return 0;
}