Pagini recente » Cod sursa (job #1288873) | Cod sursa (job #1983332) | Cod sursa (job #728831) | Cod sursa (job #858224) | Cod sursa (job #1348022)
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define Nmax 1002
#define eps 1.0 / 1e9
FILE *f = fopen ( "patrate3.in", "r" );
FILE *g = fopen ( "patrate3.out", "w" );
struct point{
double x, y;
} p[Nmax];
int N;
bool cmp ( point a, point b ){
if ( fabs ( a.x - b.x ) <= eps )
return a.y < b.y;
else
return a.x < b.x;
}
bool match ( point a, point b ){
if ( fabs ( a.x - b.x ) <= eps && fabs ( a.y - b.y ) <= eps )
return 1;
return 0;
}
bool bSearch ( point T ){
int st = 1, dr = N, mid;
while ( st <= dr ){
mid = ( st + dr ) >> 1;
if ( match ( p[mid] , T ) )
return 1;
else{
if ( cmp ( T , p[mid] ) )
dr = mid - 1;
else
st = mid + 1;
}
}
return 0;
}
int main(){
int sol = 0;
point a, b;
fscanf ( f, "%d", &N );
for ( int i = 1; i <= N; ++i )
fscanf ( f, "%lf%lf", &p[i].x, &p[i].y );
sort ( p + 1, p + N + 1, cmp );
for ( int i = 1; i < N; ++i )
for( int j = i + 1; j <= N; ++j ){
a.x = p[i].x + p[i].y - p[j].y;
a.y = p[i].y + p[j].x - p[i].x;
b.x = p[j].x + p[i].y - p[j].y;
b.y = p[j].y + p[j].x - p[i].x;
if ( bSearch( a ) && bSearch( b ) )
sol++;
}
fprintf ( g, "%d", sol >> 1 );
return 0;
}