Pagini recente » Cod sursa (job #3266107) | Cod sursa (job #2302611) | Cod sursa (job #2791622)
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define MAX_N 1500
#define EPSILON 0.0001
double modul( double a ) {
return a > 0 ? a : 0;
}
struct punct {
double x, y;
bool operator < (const punct &p) const {
if ( x == p.x )
return y < p.y;
return x < p.x;
}
bool operator > (const punct &p) const {
if ( x == p.x )
return y > p.y;
return x > p.x;
}
bool operator == (const punct &p) const {
return (modul( x - p.x ) <= EPSILON && modul( y - p.y ) <= EPSILON);
}
};
double dist2( punct a, punct b ) {
return ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y );
}
double inaltime[MAX_N];
punct pct[MAX_N];
int main() {
FILE *fin, *fout;
int n, echilaterale, egale, i, j;
fin = fopen( "triang.in", "r" );
fscanf( fin, "%d", &n );
for ( i = 0; i < n; i++ )
fscanf( fin, "%lf%lf", &pct[i].x, &pct[i].y );
fclose( fin );
std::sort( pct, pct + n );
echilaterale = 0;
for ( i = 0; i < n - 1; i++ ) {
for ( j = i + 1; j < n; j++ )
inaltime[j - (i + 1)] = sqrt( 3 * dist2( pct[i], pct[j] ) / 4 );
std::sort( inaltime, inaltime + n - (i + 1) );
egale = 0;
for ( j = 1; i < n - (j + 1); i++ ) {
if ( modul( inaltime[j] - inaltime[j - 1] ) <= EPSILON )
egale++;
else
egale = 0;
echilaterale += egale;
}
}
fout = fopen( "triang.out", "w" );
fprintf( fout, "%d", echilaterale );
fclose( fout );
return 0;
}