Cod sursa(job #828168)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 3 decembrie 2012 11:48:55
Problema Triang Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cassert>

#define x first
#define y second

using namespace std;

typedef pair<double, double> Point;

const int MaxN = 1505;
const double Eps = 1e-5;

Point Points[MaxN];
int N, Solution;

inline bool Compare(const Point &P1, const Point &P2) {
    if (abs(P1.x - P2.x) < Eps)
        if (abs(P1.y - P2.y) < Eps)
            return false;
        else
            return P1.y < P2.y;
    return P1.x < P2.x;
}

inline int Find(const Point &P) {
    if (binary_search(Points, Points + N, P, Compare))
        return 1;
    return 0;
}

void Solve() {
    sort(Points, Points + N, Compare);
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            Point P1 = Points[i], P2 = Points[j], P3;
            P3.x = 0.5 * (P1.x + P2.x) - sqrt(3.0) / 2.0 * (P2.y - P1.y);
            P3.y = 0.5 * (P1.y + P2.y) + sqrt(3.0) / 2.0 * (P2.x - P1.x);
            Solution += Find(P3);
            P3.x = 0.5 * (P1.x + P2.x) + sqrt(3.0) / 2.0 * (P2.y - P1.y);
            P3.y = 0.5 * (P1.y + P2.y) - sqrt(3.0) / 2.0 * (P2.x - P1.x);
            Solution += Find(P3);
        }
    }
    Solution /= 3;
}

void Read() {
    assert(freopen("triang.in", "r", stdin));
    assert(scanf("%d", &N) == 1);
    for (int i = 0; i < N; ++i)
        assert(scanf("%lf %lf", &Points[i].x, &Points[i].y) == 2);
}

void Print() {
    assert(freopen("triang.out", "w", stdout));
    printf("%d\n", Solution);
}

int main() {
    Read();
    Solve();
    Print();
    return 0;
}