題意:
(from luckycat)
解法:
簡單水題,判斷距離。
TAG: ad hoc
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽