Cod sursa(job #827512)

Utilizator toranagahVlad Badelita toranagah Data 2 decembrie 2012 10:27:13
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
#define x first
#define y second
const int MAX_N = 1510;
const double sin60 = sqrt(3.0) / 2;
const double cos60 = 1.0 / 2;
const double EPSILON = 1e-4;
pair<double, double> points[MAX_N];
int N;
int sol;

void read(), solve(), print();

int main() {
    read();
    solve();
    print();
    return 0;
}

bool cmp(pair<double, double> a, pair<double, double> b) {
    return (b.x - a.x > EPSILON) || (b.x - a.x < EPSILON && b.y - a.y > EPSILON);
}

void read() {
    ifstream fin("triang.in");
    fin >> N;
    for (int i = 1; i <= N; ++i) {
        fin >> points[i].x >> points[i].y;
    }
}

void solve() {
    sort(points + 1, points + N + 1);
    double x, y;
    for (int i = 1; i <= N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            x = (points[i].x + points[j].x) * cos60 - (points[j].y - points[i].y) * sin60;
            y = (points[i].y + points[j].y) * cos60 + (points[j].x - points[i].x) * sin60;
            if (binary_search(points + 1, points + N + 1, make_pair(x, y), cmp)) ++sol;
            x = (points[i].x + points[j].x) * cos60 + (points[j].y - points[i].y) * sin60;
            y = (points[i].y + points[j].y) * cos60 - (points[j].x - points[i].x) * sin60;
            if (binary_search(points + 1, points + N + 1, make_pair(x, y), cmp)) ++sol;
        }
    }
    sol /= 3;
}

void print() {
    ofstream fout("triang.out");
    fout << sol;
}