Pagini recente » Cod sursa (job #1714534) | Cod sursa (job #2537031) | Cod sursa (job #1234206) | Cod sursa (job #41600) | Cod sursa (job #827541)
Cod sursa(job #827541)
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
#define x first
#define y second
const int MAX_N = 1510;
const double sin60 = sqrt(3.0) / 2;
const double cos60 = 1.0 / 2;
const double EPSILON = 1e-4;
pair<double, double> points[MAX_N];
int N;
int sol;
void read(), solve(), print();
int main() {
read();
solve();
print();
return 0;
}
bool cmp(pair<double, double> a, pair<double, double> b) {
return ((b.x - a.x > EPSILON) || ((fabs(b.x - a.x) < EPSILON) && (b.y -a.y > EPSILON)));
}
void read() {
ifstream fin("triang.in");
fin >> N;
for (int i = 1; i <= N; ++i) {
fin >> points[i].x >> points[i].y;
}
}
void solve() {
sort(points + 1, points + N + 1, cmp);
double x, y;
for (int i = 1; i <= N; ++i) {
for (int j = i + 1; j <= N; ++j) {
x = points[i].x + (points[j].x - points[i].x) * cos60 - (points[j].y - points[i].y) * sin60;
y = points[i].y + (points[j].y - points[i].y) * cos60 + (points[j].x - points[i].x) * sin60;
if (binary_search(points + 1, points + N + 1, make_pair(x, y), cmp)) ++sol;
x = points[i].x + (points[j].x - points[i].x) * cos60 + (points[j].y - points[i].y) * sin60;
y = points[i].y + (points[j].y - points[i].y) * cos60 - (points[j].x - points[i].x) * sin60;
if (binary_search(points + 1, points + N + 1, make_pair(x, y), cmp)) ++sol;
}
}
}
void print() {
ofstream fout("triang.out");
fout << sol;
}