显示原始代码
#include <bits/stdc++.h>
using namespace std;
#define FastIO \
ios::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define endl "\n"
#define ll long long
using i64 = int64_t;
using i128 = __int128;
const int maxN = 2e5 + 10;
const int MOD = 1e9 + 7;
double x1, y11, x2, y2;
double cul(double x, double y) {
if (x >= x1 && x <= x2 && y >= y2)
return y - y2;
if (x >= x1 && x <= x2 && y <= y11)
return y11 - y;
if (y >= y11 && y <= y2 && x >= x2)
return x - x2;
if (y >= y11 && y <= y2 && x <= x1)
return x1 - x;
if (x <= x1 && y >= y2) {
double xx = x1 - x, yy = y - y2;
return sqrt(xx * xx + yy * yy);
}
if (x >= x2 && y >= y2) {
double xx = x - x2, yy = y - y2;
return sqrt(xx * xx + yy * yy);
}
if (x >= x2 && y <= y11) {
double xx = x - x2, yy = y11 - y;
return sqrt(xx * xx + yy * yy);
}
if (x <= x1 && y <= y11) {
double xx = x1 - x, yy = y11 - y;
return sqrt(xx * xx + yy * yy);
}
return 0;
}
void solve() {
int n;
cin >> n;
cin >> x1 >> y11 >> x2 >> y2;
int idx = -1;
double d = INT_MAX;
for (int i = 1; i <= n; i++) {
double x, y;
cin >> x >> y;
double dis = cul(x, y);
cout << fixed << setprecision(9) << dis << ' ';
if (dis < d) {
d = dis;
idx = i;
}
}
cout << endl << idx << endl;
}
signed main() {
FastIO int t = 1;
while (t--) solve();
return 0;
}