Pagini recente » Cod sursa (job #1351978) | Cod sursa (job #2625216) | Cod sursa (job #2335479) | Cod sursa (job #2855222) | Cod sursa (job #1021998)
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
ifstream cin("triang.in");
ofstream cout("triang.out");
const double rad3 = 1.73205081;
struct Point
{
double x;
double y;
inline bool operator==(Point other)
{
return (x == other.x &&
y == other.y);
}
};
Point p[15001];
vector<Point> myHash[7001];
int hashFunc (int nr)
{
nr = abs(nr);
return nr % 7001;
}
void adaugare (Point val)
{
myHash[hashFunc((int)val.x)].push_back(val);
}
int cauta(Point val)
{
val.x = round(val.x * 10000.0) / 10000.0;
val.y = round(val.y * 10000.0) / 10000.0;
int hashed = hashFunc((int)val.x);
for (vector<Point>::iterator i = myHash[hashed].begin(); i != myHash[hashed].end(); ++i)
if (*i == val)
return 1;
return 0;
}
void stergere (Point val)
{
int hashed = hashFunc((int)val.x);
for (vector<Point>::iterator i = myHash[hashed].begin(); i != myHash[hashed].end(); ++i)
if (*i == val)
{
myHash[hashed].erase(i);
return;
}
}
int main()
{
int n; cin >> n;
for (int i = 1; i <= n; ++i)
cin >> p[i].x >> p[i].y;
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;
adaugare (aux);
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;
adaugare (aux);
}
int cnt = 0;
for (int i = 1; i <= n; ++i)
if (cauta (p[i]) == 1)
{
++cnt;
}
cout << cnt / 3;
return 0;
}