2013年8月16日

UVa 10310 - Dog and Gopher

#include <cstdio>

double dis(double x1, double y1, double x2, double y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    double gx, gy, dx, dy;
    scanf("%lf%lf%lf%lf", &gx, &gy, &dx, &dy);
    bool find = false;
    while (n--) {
      double hx, hy;
      scanf("%lf%lf", &hx, &hy);
      if (!find) {
        if (4.0 * dis(gx, gy, hx, hy) <= dis(dx, dy, hx, hy)) {
          find = true;
          printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n", hx, hy);
        }
      }
    }
    if (!find) {
      puts("The gopher cannot escape.");
    }
  }
  return 0;
}

沒有留言:

張貼留言