题目:有一只狗和一只地鼠,n个地鼠洞,狗的奔跑速度是地鼠的二倍,问是否存在地鼠能逃跑的洞。
分析:简单题。枚举所有的洞判断即可。
说明:注意精度,不适用开根号直接利用平方比较即可。
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef struct pnode
{
double x,y;
}point;
point H[1005],D,G;
double dist( point a, point b )
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int main()
{
int n;
while ( ~scanf("%d",&n) ) {
scanf("%lf%lf%lf%lf",&G.x,&G.y,&D.x,&D.y);
for ( int i = 0 ; i < n ; ++ i )
scanf("%lf%lf",&H[i].x,&H[i].y);
int flag = 1;
for ( int i = 0 ; i < n ; ++ i )
if ( 4.0*dist( G, H[i] ) <= dist( D, H[i] ) ) {
printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n",H[i].x,H[i].y);
flag = 0;break;
}
if ( flag ) printf("The gopher cannot escape.\n");
}
return 0;
}