显示原始代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
double dis(pair<int, int> a, pair<int, int> b) {
return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}
signed main() {
int n;
cin >> n;
pair<int, int> p[4];
cin >> p[0].first >> p[0].second;
p[1].first = p[0].first;
p[3].second = p[0].second;
cin >> p[2].first >> p[2].second;
p[3].first = p[2].first;
p[1].second = p[2].second;
pair<int, int> pos[n];
for (int i = 0; i < n; i++) {
cin >> pos[i].first >> pos[i].second;
}
double res = INF;
int ans = 0;
double val = 0.0;
for (int i = 0; i < n; i++) {
if (pos[i].first >= p[0].first && pos[i].first <= p[2].first) {
val = min(abs(pos[i].second - p[0].second), abs(pos[i].second - p[2].second));
cout << fixed << setprecision(9) << val << " ";
} else if (pos[i].second >= p[0].second && pos[i].second <= p[2].second) {
val = min(abs(pos[i].first - p[0].first), abs(pos[i].first - p[2].first));
cout << fixed << setprecision(9) << val << " ";
} else {
val = min(min(dis(pos[i], p[0]), dis(pos[i], p[1])), min(dis(pos[i], p[2]), dis(pos[i], p[3])));
cout << fixed << setprecision(9) << val << " ";
}
if (val < res) {
res = val;
ans = i + 1;
}
}
cout << endl << ans << endl;
return 0;
}