Pagini recente » Cod sursa (job #1930564) | Cod sursa (job #2426056) | Cod sursa (job #2000258) | Cod sursa (job #2808914) | Cod sursa (job #1076935)
#include <iostream>
#include <fstream>
#include <unordered_set>
#define MAXN 1000
using namespace std;
struct Punct {
int x, y;
}puncte[MAXN];
int N, patrate;
unordered_set<int> hashX, hashY;
void input() {
ifstream in("patrate3.in");
in >> N;
string numere;
getline(in, numere);
for (int i = 0; i < N; ++i) {
getline(in, numere);
int size = numere.size();
bool spatiu = 0;
puncte[i].x = puncte[i].y = 0;
int semn1 = 1, semn2 = 1;
for (int j = 0; j < size; ++j) {
if (numere[j] == '.') {
continue;
}
if (numere[j] == '-') {
if (!spatiu) {
semn1 = -1;
} else {
semn2 = -1;
}
continue;
}
if (numere[j] == ' ') {
spatiu = 1;
continue;
}
if (!spatiu) {
puncte[i].x = puncte[i].x * 10 + numere[j] - '0';
} else {
puncte[i].y = puncte[i].y * 10 + numere[j] - '0';
}
}
puncte[i].x *= 10, puncte[i].y *= 10;
puncte[i].x *= semn1, puncte[i].y *= semn2;
hashX.insert(puncte[i].x), hashY.insert(puncte[i].y);
cout << puncte[i].x << " " << puncte[i].y << "\n";
}
in.close();
}
void solve() {
unordered_set<int>::iterator Xnot_found = hashX.end();
unordered_set<int>::iterator Ynot_found = hashY.end();
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (puncte[i].x <= puncte[j].x || puncte[i].y <= puncte[j].y) {
continue;
}
int x1 = puncte[i].x, y1 = puncte[i].y, x2 = puncte[j].x, y2 = puncte[j].y;
int xc = (x1 + x2) / 2, yc = (y1 + y2) / 2, xd = (x1 - x2) / 2, yd = (y1 - y2) / 2;
int x3 = (xc - yd), y3 = yc + xd, x4 = xc + yd, y4 = (yc - xd);
bool x3_found = 0, y3_found = 0, x4_found = 0, y4_found = 0;
for (int x3_offset = x3 - 10; x3_offset <= x3 + 10 && !x3_found; ++x3_offset) {
if (hashX.find(x3_offset) != Xnot_found) {
x3_found = 1;
}
}
if (!x3_found) {
continue;
}
for (int y3_offset = y3 - 10; y3_offset <= y3 + 10 && !y3_found; ++y3_offset) {
if (hashY.find(y3_offset) != Ynot_found) {
y3_found = 1;
}
}
if (!y3_found) {
continue;
}
for (int x4_offset = x4 - 10; x4_offset <= x4 + 10 && !x4_found; ++x4_offset) {
if (hashX.find(x4_offset) != Xnot_found) {
x4_found = 1;
}
}
if (!x4_found) {
continue;
}
for (int y4_offset = y4 - 10; y4_offset <= y4 + 10 && !y4_found; ++y4_offset) {
if (hashY.find(y4_offset) != Ynot_found) {
y4_found = 1;
}
}
if (!y4_found) {
continue;
}
++patrate;
}
}
}
inline void output() {
ofstream out("patrate3.out");
out << patrate;
out.close();
}
int main() {
input();
solve();
output();
return 0;
}