Cod sursa(job #3235285)

Utilizator alex210046Bratu Alexandru alex210046 Data 16 iunie 2024 19:09:24
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
ifstream f("triang.in");
ofstream g("triang.out");
int n, nr;
const float EPS=1e-5;

struct Punct {
    double x, y;
    Punct() {}
    Punct(double a, double b) : x(a), y(b) {}
    bool operator < (const Punct &A) const {
        if (abs(x - A.x) > EPS)
            return x < A.x;
        if (abs(y - A.y) > EPS)
            return y < A.y;
        return 0;
    }
    bool operator == (const Punct &A) const {
        return abs(A.x - x) < EPS && abs(A.y - y) < EPS;
    }
} a[1501];

int bs(Punct b) {
    int st = 1, dr = n;
    while (st <= dr) {
        int mij=(st + dr) / 2;
        if (a[mij] == b) return 1;
        else if (a[mij] < b) st=mij+1;
        else dr=mij-1;
    }
    return 0;
}
int main() {
    f>>n;
    for (int i=1;i<=n;i++) {
        f >> a[i].x >> a[i].y;
    }
    sort (a+1,a+n+1);
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++) {
            double x2 = a[j].x - a[i].x, y2 = a[j].y - a[i].y, x3, y3;
            x3 = a[i].x + x2 / 2 - sqrt(3) / 2 * y2;
            y3 = a[i].y + y2 / 2 + sqrt(3) / 2 * x2;
            if (bs(Punct(x3,y3))) nr++;
            x3 = a[i].x + x2 / 2 + sqrt(3) / 2 * y2;
            y3 = a[i].y + y2 / 2 - sqrt(3) / 2 * x2;
            if (bs(Punct(x3,y3))) nr++;
        }
    g<<nr/3;
    return 0;
}