Pagini recente » Progr2 | Borderou de evaluare (job #522384) | Borderou de evaluare (job #415005) | Cod sursa (job #3361494)
#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e3, INM = 1e6, INM2 = 1e6;
const long long int BINM = 1e10, INF = 1e18 + 67;
ifstream fin ("patrate3.in");
ofstream fout ("patrate3.out");
struct coords {
long long int x, y;
bool operator<(const coords& other) const {
if (x != other.x)
return x < other.x;
return y < other.y;
}
};
struct segment {
int dx, dy;
int mx, my;
bool operator<(const segment& other) const {
if (dx != other.dx)
return dx < other.dx;
if (dy != other.dy)
return dy < other.dy;
if (mx < other.mx)
return mx < other.mx;
return my < other.my;
}
};
map<segment, int> mp;
coords puncte[LIM + 9];
vector<segment> segmente;
int main() {
int n;
fin >> n;
for (int i = 1; i <= n; i++) {
string nr;
char ch;
fin >> nr;
int p = 0;
for (int i = 0; i < nr.size(); i++) {
if (nr[i] == '.')
p = i;
}
string newnr{};
for (int i = 0; i < p; i++) {
newnr += nr[i];
}
for (int i = p + 1; i < nr.size(); i++) {
newnr += nr[i];
}
long long int x = atoi(newnr.c_str()) * 10ll;
fin >> nr;
p = 0;
for (int i = 0; i < nr.size(); i++) {
if (nr[i] == '.')
p = i;
}
newnr = "";
for (int i = 0; i < p; i++) {
newnr += nr[i];
}
for (int i = p + 1; i < nr.size(); i++) {
newnr += nr[i];
}
long long int y = atoi(newnr.c_str()) * 10ll;
puncte[i] = {x, y};
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
segment s;
s.dx = abs(puncte[i].x - puncte[j].x);
s.dy = abs(puncte[i].y - puncte[j].y);
long long int xs = puncte[i].x < puncte[j].x ? puncte[i].x : puncte[j].x;
long long int ys = puncte[i].y < puncte[j].y ? puncte[i].y : puncte[j].y;
s.mx = s.dx / 2 + xs;
s.my = s.dy / 2 + ys;
//cout << s.mx << ' ' << s.my << ' ' << s.len;
if (mp.count({s.dy, s.dx, s.mx, s.my})) {
ans += mp[{s.dy, s.dx, s.mx, s.my}];
}
segmente.push_back(s);
mp[s] += 1;
}
}
fout << ans;
return 0;
}