Pagini recente » Cod sursa (job #2071081) | Cod sursa (job #702725) | Cod sursa (job #2462117) | Cod sursa (job #1753074) | Cod sursa (job #1022586)
#include <fstream>
#include <cmath>
#include <unordered_set>
using namespace std;
ifstream cin("triang.in");
ofstream cout("triang.out");
const double rad3 = 1.73205081;
struct Point
{
double x;
double y;
};
bool operator== (Point a, Point b)
{
return a.x == b.x && a.y == b.y;
}
Point p[15001];
struct MyHash{
size_t operator()(const Point& val)const
{
return hash<double>()(val.x + val.y);
}
};
unordered_set<Point, MyHash> myHash;
void adaugare (const Point& val)
{
myHash.insert (val);
}
int cauta(const Point& val)
{
if (myHash.find(val) != myHash.end())
return 1;
return 0;
}
void stergere (const Point& val)
{
myHash.erase(val);
}
int main()
{
int n; cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> p[i].x >> p[i].y;
p[i].x = round(p[i].x * 10000.0) / 10000.0;
p[i].y = round(p[i].y * 10000.0) / 10000.0;
adaugare(p[i]);
}
int cnt = 0;
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
{
double x1 = p[i].x + p[i].y * rad3
+ p[j].x - p[j].y * rad3;
double y1 = -p[i].x * rad3 + p[i].y
+ p[j].y + p[j].x * rad3;
Point aux;
aux.x = x1 / 2.0;
aux.y = y1 / 2.0;
aux.x = round(aux.x * 10000.0) / 10000.0;
aux.y = round(aux.y * 10000.0) / 10000.0;
if (cauta(aux) == 1)
++cnt;
x1 = p[i].x + p[j].x +
(p[j].y - p[i].y) * rad3;
y1 = p[i].x * rad3 + p[j].y +
p[i].y - p[j].x * rad3;
aux.x = x1 / 2.0;
aux.y = y1 / 2.0;
aux.x = round(aux.x * 10000.0) / 10000.0;
aux.y = round(aux.y * 10000.0) / 10000.0;
if (cauta(aux) == 1)
++cnt;
}
cout << cnt / 3;
return 0;
}