Pagini recente » Cod sursa (job #2980910) | Cod sursa (job #204604) | Cod sursa (job #2980918) | Cod sursa (job #577828) | Cod sursa (job #965779)
Cod sursa(job #965779)
#include <iostream>
#include <fstream>
#include <tr1/unordered_set>
#include <algorithm>
#include <cmath>
#define x first
#define y second
using namespace std;
const double EPS = 1e-6;
const double cos60 = 0.5, sin60 = 0.5 * sqrt (3);
const double PI = 3.1415926535897932384626433832795;
ifstream in ("triang.in");
ofstream out("triang.out");
typedef pair <double, double> point;
struct hasher
{
int operator () (const point &A) const
{
int ret = A.x * PI + A.y;
return ret;
}
};
struct point_equal
{
bool operator () (const point &A, const point &B) const
{
return abs (A.x - B.x) <= EPS && abs (A.y - B.y) <= EPS;
}
};
point P[1510];
tr1 :: unordered_set <point, hasher, point_equal> M;
struct comp
{
inline bool operator () (const point &A, const point &B) const
{
if (abs (A.x - A.y) <= EPS)
return A.y - B.y <= -EPS;
return A.x - B.x <= -EPS;
}
};
point get (const point &A, const point &B)
{
point now, ret;
now.x = B.x - A.x;
now.y = B.y - A.y;
ret.x = now.x * cos60 - now.y * sin60;
ret.y = now.x * sin60 + now.y * cos60;
ret.x += A.x;
ret.y += A.y;
return ret;
}
int main()
{
int N, i, j, Ans = 0;
point now;
in >> N;
for (i = 1; i <= N; i ++)
in >> P[i].x >> P[i].y;
sort (P + 1, P + N + 1, comp ());
for (i = 1; i <= N; i ++){
for (j = 1; j < i; j ++){
now = get (P[i], P[j]);
if (M.count (now))
Ans ++;
}
M.insert (P[i]);
}
out << Ans;
return 0;
}