//============================================================================
// Name : 10310.cpp
// Author : benbendog
// DATE : 2010/12/12
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
/*
* PROBLEM : given two points a,b and other points ci
* find if there is a point 2*d(a,ci) <=d(a,b)
* SOLUTION: trivial
* beware of the precision problem
*/
#include <iostream>
#include <cmath>
using namespace std;
struct point
{
double x,y;
};
bool escape(double d1,double d2);
double dist(const point & a,const point & b);
int main() {
int hole;
while(cin>>hole)
{
point p[2],h[hole];
int ans = -1;
cin>>p[0].x>>p[0].y>>p[1].x>>p[1].y;
for(int i = 0 ;i < hole ; i++)
{
cin>>h[i].x>>h[i].y;
double d1,d2;
d1 = dist(p[0],h[i]);
d2 = dist(p[1],h[i]);
//cout<<d1<<' '<<d2<<endl;
if(escape(d1,d2))if(ans==-1)ans = i;
}
if(ans!=-1)
printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n",h[ans].x,h[ans].y);
else
cout<<"The gopher cannot escape."<<endl;
}
return 0;
}
bool escape(double d1,double d2)
{
if(2*d1 < d2)return true;
if(abs(2*d1-d2) < 1e-6)return true;
return false;
}
double dist(const point & a,const point & b)
{
double v1,v2;
v1 = a.x - b.x;
v2 = a.y - b.y;
return sqrt(v1*v1+v2*v2);
}
- Dec 12 Sun 2010 15:35
UVA 10310
全站熱搜
留言列表