// Run time: 0.010
#include <stdio.h>
double gx, gy, dx, dy;
bool test(double arr[2]);
double distance(double x, double y, double arr[2]);
int main()
{
int n;
int i;
while (scanf("%d", &n) != EOF)
{
double hole[n][2];
scanf("%lf %lf %lf %lf", &gx, &gy, &dx, &dy);
for ( i = 0; i < n; i++)
scanf("%lf %lf", &hole[i][0], &hole[i][1]);
for ( i = 0; i < n; i++)
if (test(hole[i]))
break;
printf("The gopher ");
if (i == n)
printf("cannot escape.\n");
else
printf("can escape through the hole at (%.3lf,%.3lf).\n", hole[i][0], hole[i][1]);
}
return 0;
}
bool test(double arr[2])
{
double d, g;
d = distance(dx, dy, arr);
g = distance(gx, gy, arr);
// without sqrt, so we should use 4 times to compare.
if (4*g <= d)
return true;
else
return false;
}
double distance(double x, double y, double arr[2])
{
return (arr[0]-x)*(arr[0]-x)+(arr[1]-y)*(arr[1]-y);
}
2009年3月8日 星期日
Q10310: Dog and Gopher
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言