Cod sursa(job #2432428)

Utilizator OctavianVasileVasileOctavian OctavianVasile Data 23 iunie 2019 17:09:07
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("patrate3.in");
ofstream fout ("patrate3.out");
#define NMAX 1003
double A24, B24;
int ans, n;
struct Punct{
    double x;
    double y;
}v [NMAX];
bool cmp (Punct A, Punct B){
    if (A.x == B.x)return A.y > B.y;
    return A.x > B.x;
}
bool BS (Punct A){
    int st = 1, dr = n, med;
    while (st <= dr){
        med = (st + dr) / 2;
        if (A.x == v [med].x && A.y == v [med].y)
            return 1;
        if (cmp (v [med], A) == 1)st = med + 1;
        else dr = med - 1;
    }
    return 0;
}
void valid (Punct A, Punct B){
    Punct M, a, b;
    M.x = (A.x + B.x) / 2;
    M.y = (A.y + B.y) / 2;
    double K1 = abs (A.x - M.x);
    double K2 = abs (A.y - M.y);
    if (A.y > B.y){
        a.x = M.x - K2;
        a.y = M.y + K1;
        b.y = M.y - K1;
        b.x = M.x + K2;
    }
    else{
        a.x = M.x - K2;
        a.y = M.y - K1;
        b.y = M.y + K1;
        b.x = M.x + K2;
    }
    if (BS (a) && BS (b))ans ++;
}
int main (){
    fin >> n;
    for (int i = 1; i <= n; i ++){
        fin >> A24 >> B24;
        v [i].x = round (A24 * 10000.0);
        v [i].y = round (B24 * 10000.0);
    }
    sort (v + 1, v + n + 1, cmp);
    for (int i = 1; i < n; i ++)
        for (int j = i + 1; j <= n; j ++)
            valid (v [i], v [j]);
    fout << ans / 2;
    return 0;
}