Cod sursa(job #2907667)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 31 mai 2022 00:22:16
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.8 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("triang.in");
ofstream fout ("triang.out");

void usain_bolt()
{
    ios::sync_with_stdio(false);
    fin.tie(0);
}

const int N = 2e3 + 5;
const double EPS = 1e-3;

pair < double, double > a[N];

bool cmp(pair < double, double > a, pair < double, double > b)
{
    return (a.first < b.first || (fabs(a.first - b.first) < EPS && a.second < b.second));
}

bool solve(pair < double, double > find_it, int n)
{
    int left = 1, right = n;
    while (left <= right) {
        int mid = (left + right) >> 1;
        if (fabs(a[mid].first - find_it.first) < EPS && fabs(a[mid].second - find_it.second) < EPS)
            return true;
        if (a[mid].first > find_it.first ||
            (fabs(a[mid].first - find_it.first) < EPS && a[mid].second > find_it.second))
            right = mid - 1;
        else
            left = mid + 1;
    }
    return 0;
}

int main()
{
    usain_bolt();

    int n, sol = 0;
    pair < double, double > find_it;

    fin >> n;
    for (int i = 1; i <= n; ++i)
        fin >> a[i].first >> a[i].second;
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            find_it.first = a[i].first * 0.5 + a[j].first * 0.5 - sqrt(3) * 0.5 * (a[i].second - a[j].second);
            find_it.second = a[i].second * 0.5 + a[j].second * 0.5 - sqrt(3) * 0.5 * (a[j].first - a[i].first);
            sol += solve(find_it, n);
            find_it.first = a[i].first * 0.5 + a[j].first * 0.5 + sqrt(3) * 0.5 * (a[i].second - a[j].second);
            find_it.second = a[i].second * 0.5 + a[j].second * 0.5 + sqrt(3) * 0.5 * (a[j].first - a[i].first);
            sol += solve(find_it, n);
        }
    }
    fout << sol / 3;
    return 0;
}