Pagini recente » Cod sursa (job #991815) | Cod sursa (job #2428200) | Cod sursa (job #2548159) | Cod sursa (job #477917) | Cod sursa (job #2876211)
#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<<50)
#define EPS 0.000000001
struct POINT {
int x, y;
};
double getpanta( const POINT& a, const POINT& b ) {
if ( a.x == b.x )
return INF;
return ( (double)b.y - a.y ) / ( b.x - a.x );
}
struct DREAPTA {
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;
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[i], v[j] );
drepte.push_back({x});
}
}
sort ( drepte.begin(), drepte.end() );
ans = 0;
for ( i = 1; i < drepte.size(); i++ ) {
j = i;
while ( j < drepte.size() && fabs( drepte[i].panta - drepte[j].panta ) <= EPS )
j++;
ans += ( j - i ) * ( j - i - 1 ) / 2;
}
cout << ans;
return 0;
}