Cod sursa(job #2676957)

Utilizator Fantastic_Mantudor voicu Fantastic_Man Data 25 noiembrie 2020 15:45:42
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.67 kb
#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;
}