Pagini recente » Cod sursa (job #3225080) | Cod sursa (job #2836546) | Cod sursa (job #2642346) | Cod sursa (job #1553951) | Cod sursa (job #2676957)
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <ctype.h>
using namespace std;
const int NMAX = 1000;
struct pct {
int x; int y;
} v[NMAX + 1], m, a, b, d;
bool operator < ( pct a, pct b ) {
if ( a.x == b.x )
return a.y < b.y;
return a.x < b.x;
}
bool operator == ( pct a, pct b ) {
return ( a.x == b.x && a.y == b.y );
}
bool operator <= ( pct a, pct b ) {
return (a < b || a == b );
}
FILE *fin;
int nr() {
int ch, sign = 1, nr = 0;
while ( isspace( ch = fgetc ( fin ) ) );
if ( ch == '-' ) {
sign = -1;
ch = fgetc ( fin );
}
do {
if ( isdigit ( ch ) )
nr = nr * 10 + ch - '0';
} while ( ! isspace( ch = fgetc ( fin ) ));
return sign * nr;
}
int n;
int bs ( pct x ) {
int pos = -1;
for ( int step = (1 << 9); step; step >>= 1 )
if ( pos + step <= n && v[pos + step] <= x )
pos += step;
return ( pos != -1 && v[pos] == x );
}
ofstream fout ( "patrate3.out" );
int main() {
int i, j, cate;
fin = fopen( "patrate3.in", "r" );
fscanf ( fin, "%d", &n );
for ( i = 1; i <= n; i++ ) {
v[i].x = nr();
v[i].y = nr();
}
fclose ( fin );
sort ( v + 1, v + n + 1 );
cate = 0;
for ( i = 1; i < n; i++ )
for ( j = i + 1; j <= n; j++ ) {
d.x = v[i].y - v[j].y;
d.y = v[i].x - v[j].x;
a.x = v[i].x + d.x;
a.y = v[i].y - d.y;
b.x = v[j].x + d.x;
b.y = v[j].y - d.y;
if ( bs ( a ) && bs ( b ) )
cate++;
}
fout << cate / 2;
return 0;
}