Pagini recente » Cod sursa (job #89548) | Cod sursa (job #1991373) | Cod sursa (job #713791) | Cod sursa (job #2778418) | Cod sursa (job #1076891)
#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;
for (int j = 0; j < size; ++j) {
if (numere[j] == '.') {
continue;
}
if (numere[j] == ' ') {
spatiu = 1;
} else {
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;
hashX.insert(puncte[i].x), hashY.insert(puncte[i].y);
}
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 - 1; ++i) {
for (int j = i + 1; 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);
if (hashX.find(x3) != Xnot_found && hashY.find(y3) != Ynot_found
&& hashX.find(x4) != Xnot_found && hashY.find(y4) != Ynot_found) {
++patrate;
}
}
}
}
inline void output() {
ofstream out("patrate3.out");
out << patrate;
out.close();
}
int main() {
input();
solve();
output();
return 0;
}