都是莫名其妙的几何水题。要刷到什么时候我才能刷到高难度。
比较一下逃脱点到田鼠和狗的距离就好了。
注意一下是以空行来区分每个case。
#include<iostream>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
struct point{double x,y;int id;};
point hole,ans,dog,gopher;
const double eps = 1e-6;
void dist(point hole,double &todog,double &togop)
{
todog = sqrt ( (dog.x - hole.x)*(dog.x - hole.x)+
(dog.y-hole.y)*(dog.y-hole.y) );
togop = sqrt ( (gopher.x - hole.x)*(gopher.x - hole.x)+
(gopher.y-hole.y)*(gopher.y-hole.y) );
}
char str[100];
int main()
{
//freopen("in.txt","r",stdin);
while( ~scanf("%lf %lf %lf %lf\n",&gopher.x,&gopher.y,&dog.x,&dog.y))
{
int flag = 1;
double todog,togop;
while(gets(str))
{
if( strlen(str)==0)break;
sscanf(str,"%lf%lf",&hole.x,&hole.y);
dist(hole,todog,togop);
if( flag && togop < todog *0.5)
{
printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n",
hole.x,hole.y);
flag = 0;
}
}
if( flag )
puts("The gopher cannot escape.");
}
return 0;
}