Pagini recente » Cod sursa (job #653922) | Cod sursa (job #2802905) | Cod sursa (job #719160) | Cod sursa (job #581886) | Cod sursa (job #3285908)
#include <fstream>
#include <set>
#include <vector>
#include <cmath>
using namespace std;
ifstream cin("triang.in");
ofstream cout("triang.out");
struct point {
double x, y;
bool operator<(const point& other) const {
if (this->x == other.x) {
return this->y < other.y;
}
return this->x < other.x;
}
point() {}
point(const double& _x, const double& _y) : x(_x), y(_y) {}
};
int n, ans;
double x, y;
vector<point> points;
set<point> fr;
inline void approx(double& val) {
val = round(val * 10000.0) / 10000.0;
}
void solve(point a, point b) {
point mid((a.x + b.x) / 2, (a.y + b.y) / 2);
double len = sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
double dist = len * sqrt(3) / 2.0;
double slope = (b.y - a.y) / (b.x - a.x);
double next_x = mid.x + dist * cos(atan(-1.0 / slope));
double next_y = mid.y + dist * sin(atan(-1.0 / slope));
approx(next_x);
approx(next_y);
cout << next_x << ' ' << next_y << '\n';
if (fr.count(point(next_x, next_y))) {
++ans;
}
next_x = mid.x - dist * cos(atan(-1.0 / slope));
next_y = mid.y - dist * sin(atan(-1.0 / slope));
approx(next_x);
approx(next_y);
cout << next_x << ' ' << next_y << '\n';
if (fr.count(point(next_x, next_y))) {
++ans;
}
}
int main()
{
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x >> y;
approx(x);
approx(y);
cout << x << ' ' << y << '\n';
points.emplace_back(x, y);
fr.emplace(x, y);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j) {
solve(points[i], points[j]);
}
}
}
cout << ans / 6;
return 0;
}