Pagini recente » Cod sursa (job #3134242) | Cod sursa (job #42528) | Cod sursa (job #360388) | Cod sursa (job #2371077) | Cod sursa (job #3235285)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
ifstream f("triang.in");
ofstream g("triang.out");
int n, nr;
const float EPS=1e-5;
struct Punct {
double x, y;
Punct() {}
Punct(double a, double b) : x(a), y(b) {}
bool operator < (const Punct &A) const {
if (abs(x - A.x) > EPS)
return x < A.x;
if (abs(y - A.y) > EPS)
return y < A.y;
return 0;
}
bool operator == (const Punct &A) const {
return abs(A.x - x) < EPS && abs(A.y - y) < EPS;
}
} a[1501];
int bs(Punct b) {
int st = 1, dr = n;
while (st <= dr) {
int mij=(st + dr) / 2;
if (a[mij] == b) return 1;
else if (a[mij] < b) st=mij+1;
else dr=mij-1;
}
return 0;
}
int main() {
f>>n;
for (int i=1;i<=n;i++) {
f >> a[i].x >> a[i].y;
}
sort (a+1,a+n+1);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
double x2 = a[j].x - a[i].x, y2 = a[j].y - a[i].y, x3, y3;
x3 = a[i].x + x2 / 2 - sqrt(3) / 2 * y2;
y3 = a[i].y + y2 / 2 + sqrt(3) / 2 * x2;
if (bs(Punct(x3,y3))) nr++;
x3 = a[i].x + x2 / 2 + sqrt(3) / 2 * y2;
y3 = a[i].y + y2 / 2 - sqrt(3) / 2 * x2;
if (bs(Punct(x3,y3))) nr++;
}
g<<nr/3;
return 0;
}