Pagini recente » Cod sursa (job #250468) | Cod sursa (job #2627081) | Cod sursa (job #2791807)
#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 );
}
int ind;
int poz[MAX_N];
double inaltime[MAX_N][MAX_N], h[MAX_N];
punct pct[MAX_N];
bool cmp ( int a, int b ) {
return inaltime[ind][a] < inaltime[ind][b];
}
int main() {
FILE *fin, *fout;
int n, echilaterale, egale, i, j, k;
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 );
for ( i = 0; i < n - 1; i++ ) {
for ( j = i + 1; j < n; j++ )
inaltime[i][j] = sqrt( 3 * dist2( pct[i], pct[j] ) / 4 );
}
echilaterale = 0;
for ( i = 0; i < n - 1; i++ ) {
for ( j = i + 1; j < n; j++ )
poz[j] = j;
ind = i;
std::sort( poz + i + 1, poz + n, cmp );
egale = 0;
for ( j = i + 2; j < n; j++ ) {
if ( modul( inaltime[i][poz[j]] - inaltime[i][poz[j - 1]] ) <= EPSILON )
egale++;
else
egale = 0;
for ( k = 0; k < egale; k++ ) {
if ( abs( inaltime[poz[j - k - 1]][poz[j]] - inaltime[i][poz[j]] ) <= EPSILON ) {
echilaterale++;
}
}
}
}
fout = fopen( "triang.out", "w" );
fprintf( fout, "%d", echilaterale );
fclose( fout );
return 0;
}