Pagini recente » Cod sursa (job #564429) | Cod sursa (job #1802728) | Cod sursa (job #2101343) | Cod sursa (job #1635820) | Cod sursa (job #2892161)
#include <iostream>
#include <algorithm>
#include <math.h>
#define lol long long
using namespace std;
FILE * fin = fopen("triang.in", "r");
FILE * fout = fopen("triang.out", "w");
int n;
double eps = 1e-3;
struct point
{
double x, y;
};
bool comp(point p1, point p2)
{
if (p1.x - eps > p2.x || p1.x + eps < p2.x)
return p1.x < p2.x;
if (p1.y - eps > p2.y || p1.y + eps < p2.y)
return p1.y < p2.y;
return false;
}
point points[1505];
int main()
{
fscanf(fin, "%d", &n);
for (int i = 0; i < n; i++)
fscanf(fin, "%lf %lf", &points[i].x, &points[i].y);
sort(points, points + n, comp);
lol countt = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i == j)
continue;
// rotate it both ways, verify if it exists
double newX = points[i].x - points[j].x;
double newY = points[i].y - points[j].y;
double sin60 = sqrt(3) / 2;
point p1 = {newX / 2 - sin60 * newY + points[j].x,
newX * sin60 + newY / 2 + points[j].y};
countt += binary_search(points, points + n, p1, comp);
point p2 = {newX / 2 + sin60 * newY + points[j].x,
- newX * sin60 + newY / 2 + points[j].y};
countt += binary_search(points, points + n, p2, comp);
}
}
fprintf(fout, "%lld\n", countt / 6);
}