1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <stdio.h> #define inf 0x3f3f3f3f; #define maxn 205
double ax[maxn], ay[maxn], bx[maxn], by[maxn];
int main() {
int n, m, i, j; while (~scanf("%d%d", &n, &m)) { double X, Y; scanf("%lf%lf", &X, &Y); for (i = 1; i <= n; ++i) { scanf("%lf%lf", &ax[i], &ay[i]); } for (i = 1; i <= m; ++i) { scanf("%lf%lf", &bx[i], &by[i]); } int a = 0, b = 0; double ans = inf; for (i = 1; i <= n; ++i) { double len = sqrt((ax[i] - X) * (ax[i] - X) + (ay[i] - Y) * (ay[i] - Y)); for (j = 1; j <= m; ++j) { double cur = len + sqrt((ax[i] - bx[j]) * (ax[i] - bx[j]) + (ay[i] - by[j]) * (ay[i] - by[j])); if (cur < ans) { ans = cur; a = i, b = j; } } } printf("%.4lf %d %d\n", ans, a, b); } return 0; }
|