Cod sursa(job #2661540)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 22 octombrie 2020 11:23:12
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <bits/stdc++.h>
#define ABS(x) ((x) >= 0 ? (x) : -(x))
// https://stackoverflow.com/questions/2861904/how-to-find-coordinates-of-a-2d-equilateral-triangle-in-c

using namespace std;
 
ifstream fin("triang.in");
ofstream fout("triang.out");
 
const double eps = 1e-4;
 
struct punct {
    double x, y;
 
    bool operator < (const punct& A) const {
        if(ABS(x - A.x) <= eps)
            return y + eps  <= A.y;
        return x + eps <= A.x;
    }
};
 
punct rotire(const punct& A, const punct& B) {
    static double c = 0.5, s = sqrt(3) / 2;
    double dx = B.x - A.x, 
           dy = B.y - A.y; 
    punct C;
    C.x = dx * c - dy * s + A.x;
    C.y = dx * s + dy * c + A.y;
    return C;
}
 
int main() {
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);
    fin.tie(nullptr);
    fout.tie(nullptr);
    int N;
    fin >> N;
    set < punct > S;
    int ans = 0;
    while(N--) {
        punct A;
        fin >> A.x >> A.y;
        for(auto& B : S) {
            punct M = rotire(A, B);
            if(S.find(M) != S.end())
                ++ans;
        }
        S.insert(A);
    }
    fout << ans;
}