Cod sursa(job #965554)

Utilizator ericptsStavarache Petru Eric ericpts Data 24 iunie 2013 10:15:44
Problema Triang Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <cstdio>
#include <algorithm>
#include <utility>
#include <tr1/unordered_set>
#include <cmath>

#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;
    }
};

tr1::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;
}