Pagini recente » Cod sursa (job #2644962) | Cod sursa (job #2518810) | Cod sursa (job #639790) | Cod sursa (job #1611334) | Cod sursa (job #1021994)
#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 * 1000.0) / 1000.0;
val.y = round(val.y * 1000.0) / 1000.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
y + 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 * 1000.0) / 1000.0;
aux.y = round(aux.y * 1000.0) / 1000.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 * 1000.0) / 1000.0;
aux.y = round(aux.y * 1000.0) / 1000.0;
adaugare (aux);
}
int cnt = 0;
for (int i = 1; i <= n; ++i)
if (cauta (p[i]) == 1)
{
++cnt;
cout << "gasit: " <<
p[i].x << " " << p[i].y << endl;
}
cout << cnt / 3;
return 0;
}