Translate

Views

Saturday, January 6, 2024

Solution UVA: 10310 - Dog and Gopher


 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10310 - Dog and Gopher AcceptedC++110.0000.0004521 mins ago


Suggest:

- Because the dog run better x2 than mouse 

=> mouse escape <=> distance(mouse -> hole) * 2 < distance(dog -> hole)


#include<bits/stdc++.h>
using namespace std;

double sqr(double x){
    return x*x;
}

double distance(double x1, double y1, double x2, double y2){
    return sqrt(sqr(x1-x2) + sqr(y1-y2));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
   
    int n;
    double x1, x2, y1, y2;
   
    while(cin >> n >> x1 >> y1 >> x2 >> y2){
        vector<pair<double, double>> a;
       
        while(n--){
            double x, y;    cin >> x >> y;
            a.push_back({x,y});
        }
       
        bool escape = false;
        for(auto p:a){
           
            double x = p.first;
            double y = p.second;
           
            double d1 = distance(x, y, x1, y1);
            double d2 = distance(x, y, x2, y2);
           
            if (d1*2 - d2 < 0.000001){
                escape = true;
                cout<<"The gopher can escape through the hole at ("<<fixed<<setprecision(3)<<x<<","<<y<<").\n";
                break;
            }
        }
       
        if (not escape)
            cout<<"The gopher cannot escape.\n";
    }
}



 

No comments: