Cod sursa(job #2555401)

Utilizator arckerDolteanu Gabriel arcker Data 23 februarie 2020 23:21:02
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <bits/stdc++.h>
 
#define x first
#define y second
 
using namespace std;
const double EPS = 1e-6;
const double PI = 3.1415926535897932384626433832795;
typedef pair<double,double> point;
 
point P[1502];
 
struct Hasher{
 
    int operator()(const point &A)const
    {
        const double fst = A.x * PI + A.y;
        return int(fst);
    }
 
};
 
struct Hash_eq{
    bool operator()(const point &A,const point &B)const
    {
        return abs(A.x-B.x) <= EPS && abs(A.y-B.y) <= EPS;
    }
};
 
unordered_set<point,Hasher,Hash_eq> T;
 
int n;
const double cs = cos(PI * 60 / 180.0),sn = sin(PI * 60 / 180.0);
 
point rotate(const point &p)
{
    point ret;
 
    ret.x = p.x * cs - p.y * sn;
    ret.y = p.x * sn + p.y * cs;
 
    return ret;
}
 
int main()
{
    freopen("triang.in", "r", stdin);
    freopen("triang.out", "w", stdout);
 
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; ++ i)
        scanf("%lf%lf",&P[i].x,&P[i].y);
 
 
    sort(P+1,P+n+1);
 
    int show = 0;
 
    point sought;
 
    for(int i = 1 ; i <= n ; ++ i){
 
        for(int j = 1 ; j < i ; ++ j){
 
            sought.x = P[j].x - P[i].x;
            sought.y = P[j].y - P[i].y;
 
            sought = rotate(sought);
 
            sought.x += P[i].x;
            sought.y += P[i].y;
 
            if(T.count(sought))
                ++show;
 
        }
 
        T.insert(P[i]);
 
    }
 
    printf("%d\n",show);
 
    return 0;
}