Cod sursa(job #1545610)

Utilizator cbanu96Banu Cristian cbanu96 Data 6 decembrie 2015 21:36:04
Problema Triang Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.95 kb
#include <cstdio>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

double EPS = 0.0001;

double eps_cmp(double x, double y) {
    if ((x-y) < -EPS)
        return -1;
    if ((x-y) > EPS)
        return 1;
    return 0;
}

struct point {
    double x;
    double y;

    point(double _x, double _y) :
        x(_x), y(_y) {}

    inline bool operator<(const point& other) const {
        if (eps_cmp(x, other.x) == 0)
            return eps_cmp(y, other.y) < 0;
        return eps_cmp(x, other.x) < 0;
    }
};

set<point> points;
vector<point> P;
int n;

double T(double x_a, double y_a,
         double x_b, double y_b,
         double& x_c, double& y_c,
         double cosphi, double sinphi) {
    double dx = x_b - x_a;
    double dy = y_b - y_a;
    x_c = dx * cosphi - dy * sinphi + x_a;
    y_c = dx * sinphi + dy * cosphi + y_a;
}

int main() {
    freopen("triang.in", "r", stdin);
    freopen("triang.out", "w", stdout);

    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        P.push_back(point(x, y));
    }

    points.insert(P[0]);
    int ans = 0;

    for (int i = 1; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            double x_a = P[i].x,
                   y_a = P[i].y,
                   x_b = P[j].x,
                   y_b = P[j].y,
                   x_c, y_c;

            T(x_a, y_a, x_b, y_b, x_c, y_c, 1./2, sqrt(3)/2);
/*            fprintf(stderr, "%lf %lf\n", x_a, y_a);
            fprintf(stderr, "%lf %lf\n", x_b, y_b);
            fprintf(stderr, "%lf %lf\n", x_c, y_c); */
            if (points.find(point(x_c, y_c)) != points.end())
                ans++;

            T(x_a, y_a, x_b, y_b, x_c, y_c, 1./2, -sqrt(3)/2);
            /*fprintf(stderr, "%lf %lf\n", x_c, y_c); */
            if (points.find(point(x_c, y_c)) != points.end())
                ans++;
        }
        points.insert(P[i]);
    }

    printf("%d\n", ans);
    
    return 0;
}