2610:Dog & Gopher

keyword

幾何 C++

概要

平面上に犬とリスがいる。穴がいくつかある。犬はリスの2倍の速度で動く。リスが犬より早くたどり着けるような穴があるかどうか判定する問題。
距離が2倍以上離れているかどうかだけ見れば良い。出力の際にピリオド忘れてWAもらったけど他は大丈夫。long double使ったのは誤差基準が分からなかったから。

int main(){
    long double x, y;
    complex<long double> gopher, dog, hole;
    cin >> x >> y;
    gopher = complex<long double>(x,y);
    cin >> x >> y;
    dog = complex<long double>(x,y);

    while(cin >> x >> y){
        hole = complex<long double>(x,y);
        if(2.0*abs(gopher - hole) <= abs(dog - hole)){
            printf("The gopher can escape through the hole at (%.3llf,%.3llf).\n", x, y);
            return 0;
        }
    }
    printf("The gopher cannot escape.\n");
}