我是個對電腦科學有興趣的學生,我會貼上我的學習歷程及生活心情,也請大大們多多指教。 :)

2015年6月16日 星期二

[UVa] 10310 - Dog and Gopher

題目網址: https://goo.gl/rww5i1

題意:
(from luckycat)


解法:
簡單水題,判斷距離。

TAG: ad hoc

注意:

程式碼:
/**
* Tittle: 10310 - Dog and Gopher
* Author: Cheng-Shih, Wong
* Date: 2015/06/16
*/
// include files
#include <bits/stdc++.h>
using namespace std;
// definitions
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
#define clr(x,v) memset( x, v, sizeof(x) )
#define N 1005
// declarations
int n;
double dx, dy, gx, gy;
double hx[N], hy[N];
// functions
void input( void )
{
scanf( "%lf%lf%lf%lf", &gx, &gy, &dx, &dy );
FOR( i, 1, n )
scanf( "%lf%lf", &hx[i], &hy[i] );
}
double dis( double ax, double ay, double bx, double by )
{
double delx = (ax-bx);
double dely = (ay-by);
return sqrt( delx*delx+dely*dely );
}
void solve( void )
{
int hole = 0;
FOR( i, 1, n ) {
if( 2*dis(gx,gy,hx[i],hy[i]) <= dis(dx,dy,hx[i],hy[i]) ) {
hole = i;
break;
}
}
if( hole )
printf( "The gopher can escape through the hole at (%.3lf,%.3lf).\n", hx[hole], hy[hole] );
else
puts("The gopher cannot escape.");
}
// main function
int main( void )
{
// input
while( scanf( "%d", &n )==1 ) {
input();
solve();
}
return 0;
}

沒有留言:

張貼留言

任何意見都樂意傾聽