Pagini recente » Cod sursa (job #2042454) | Cod sursa (job #2663012) | Cod sursa (job #2042200) | Cod sursa (job #1019319) | Cod sursa (job #1197101)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream f ("patrate3.in");
ofstream g ("patrate3.out");
const int nmax = 1001;
const double e = 0.00001;
struct punct {
double x, y;
bool operator == (const punct p) {
return (fabs(p.x - x) < e && fabs(p.y - y < e));
}
bool operator <(const punct p) {
if (fabs(p.x - x) < e) return y < p.y;
else return x < p.x;
}
bool operator >(const punct p) {
if (fabs(p.x - x) < e) return y > p.y;
else return x > p.x;
}
};
int n, sol;
punct p[nmax];
void citeste () {
f >> n;
for (int i = 1; i <= n; i++) {
f >> p[i].x >> p[i].y;
}
}
inline bool conditie (punct a, punct b) {
if (fabs(a.x - b.x) < e) return (b.y - a.y >= e);
return b.x - a.x >= e;
}
bool cauta (punct a) {
int st = 1, dr = n, mid;
while (st <= dr) {
mid = (st + dr) / 2;
if (p[mid] == a) return true;
else if (p[mid] < a) st = mid + 1;
else dr = mid - 1;
}
return false;
}
void rezolva () {
punct a, b;
for (int i = 1; i < n; ++i)
for (int j = i + 1; j <= n; ++j) {
a.x = p[i].x + p[i].y - p[j].y;
a.y = p[i].y + p[j].x - p[i].x;
b.x = p[i].y + p[j].x - p[j].y;
b.y = p[j].x + p[j].y - p[i].x;
if (cauta(a) && cauta(b)) sol++;
//cout << a.x << ' ' << a.y;
}
}
int main () {
citeste();
sort(p + 1, p + n + 1, conditie);
rezolva();
g << sol / 2 << '\n';
}