Cod sursa(job #2789657)

Utilizator mateitudordmDumitru Matei mateitudordm Data 27 octombrie 2021 19:38:02
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.67 kb
#include <bits/stdc++.h>
#define PI 3.14159265
#define sin1 sin(PI / 3)
#define cos1 cos(PI / 3)
#define sin2 sin(-PI / 3)
#define cos2 cos(-PI / 3)
#define eps 0.001

using namespace std;

struct pct
{
    double x, y;
    bool operator<(const pct &a) const
    {
        if (abs(x - a.x) <= eps)
            return y + eps <= a.y;
        return x + eps <= a.x;
    }
};
set<pct> v;
set<pct>::iterator it1, it2, aux;

int main()
{
    ifstream cin("triang.in");
    ofstream cout("triang.out");
    int i, cnt = 0, n;
    double x, y;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> x >> y;
        pct m;
        m.x = x;
        m.y = y;
        v.insert(m);
    }
    for (it1 = v.begin(); it1 != v.end(); it1++)
    {
        aux = it1;
        for (it2 = (++aux); it2 != v.end(); it2++)
        {
            double x1, x2, y1, y2, xx, yy;
            x1 = (*it1).x, x2 = (*it2).x, y1 = (*it1).y, y2 = (*it2).y;
            y2 -= y1, x2 -= x1;
            xx = x2 * cos1 - y2 * sin1;
            yy = x2 * sin1 + y2 * cos1;
            y1 += yy, x1 += xx;
            pct m;
            m.x = x1;
            m.y = y1;
            if (abs((*v.find(m)).y - y) < eps && abs((*v.find(m)).x - x) < eps)
                cnt++;
            x1 = (*it1).x, x2 = (*it2).x, y1 = (*it1).y, y2 = (*it2).y;
            y2 -= y1, x2 -= x1;
            xx = x2 * cos2 - y2 * sin2;
            yy = x2 * sin2 + y2 * cos2;
            y1 += yy, x1 += xx;
            m.x = x1;
            m.y = y1;
            if (abs((*v.find(m)).y - y) <= eps && abs((*v.find(m)).x - x) <= eps)
                cnt++;
        }
    }
    cout << cnt;
}