题目大意:
一只老鼠和一条狗,地上有n个洞。现在给出老鼠和狗的初始位置,老鼠朝准一个洞跑去,狗以2倍的速度跑过去,看看能不能追上,如果狗先到,那么就吃掉它,如果鼠先到,那么就逃了。
求出第一个鼠能逃脱的洞的位置,如果不能逃,那么就被吃掉。
这个题目直接枚举所有洞就行了,注意是2倍的鼠的距离小于等于狗的距离。同时到达不会被吃掉,这个地方wa了一次。
代码:
#include <iostream>
#include<cstdio>
#include <cstdlib>
#include<cmath>
using namespace std;
const int MaxN = 1010;
int n;
struct POINT
{
double x,y;
}point[MaxN];
struct POINT pDog,pMouse;
double GetDis(POINT p1, POINT p2)
{
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
int main()
{
while (scanf("%d %lf %lf %lf %lf", &n, &pMouse.x, &pMouse.y, &pDog.x, &pDog.y) != EOF)
{
int flag = 1;
for (int i = 0; i < n; ++ i)
{
scanf("%lf %lf", &point[i].x, &point[i].y);
}
for (int i = 0; i < n; ++ i)
{
double s1 =2.0 * GetDis(pMouse, point[i]);
double s2 = GetDis(pDog, point[i]);
if ( s1 <= s2)
{
flag = 0;
printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n", point[i].x, point[i].y);
break;
}
}
if (flag)
{
printf("The gopher cannot escape.\n");
}
}
return 0;
}