Zoj 1860:dog & Gopher__zoj

Source: Internet
Author: User
Tags gopher time limit
Dog & Gopher Time limit:2 Seconds Memory limit:65536 KB A large field has a Dog and a Gopher. The dog wants to eat the gopher while the Gopher wants to run to safety through one of several gopher holes dug in the the SU Rface of the field.

Neither the dog nor the gopher is a math major; However, neither is entirely stupid. The Gopher decides on a particular gopher hole and heads for this hole in a straight line at a fixed speed. The dog, which is very good at Reading body language, anticipates which hole the Gopher has, chosen, and heads at double th E speed of the gopher to the hole, where it intends to gobble up the gopher. If the dog reaches the hole, the gopher gets gobbled; Otherwise, the Gopher escapes.

You are have been retained by the gopher to select a hole through the It can escape, if which a such hole.


Input

The "a" of input contains four floating point numbers:the (x,y) coordinates of the gopher followed by the (X,y) CO Ordinates of the dog. Subsequent lines of input each contain two floating point numbers:the (x,y) coordinates of a gopher hole. All distances are into metres, to the nearest mm.

Input contains multiple test cases. Subsequent test cases are separated with a single blank line.


Output

Your output for each test case should consist's a single line. If The Gopher can escape the line should read, the Gopher can escape through the hole at (x,y). Identifying Te hole to the nearest mm. otherwise the output line should read "The Gopher cannot escape." If the gopher may escape through more than one hole, choose the one. There are not more than 1000 gopher holes and all coordinates are between-10000 and +10000.


Sample Input

1.000 1.000 2.000 2.000
1.500 1.500

2.000 2.000 1.000 1.000
1.500 1.500
2.500 2.500


Sample Output

The gopher cannot escape.
The gopher can escape through the hole at (2.500,2.500).

Source:university of Waterloo Local Contest 1999.09.25

lost in the valley of the birds, flying alone in this huge world, but do not know where to fly to the side ...

#include <iostream> #include <cstdio> #include <sstream> #include <algorithm> #include <cstr  
Ing> #include <cmath> using namespace std;  
    struct point {double x,y;  
int id;  
};  
Point Hole,ans,dog,gopher;  
Const double EPS = 1e-6; void Dist (point hole,double &todog,double &togop) {Todog =sqrt (dog.x-hole.x) * (dog.x-hole.x) + (dog.y-h  
    OLE.Y) * (DOG.Y-HOLE.Y));  
Togop = sqrt (gopher.x-hole.x) * (gopher.x-hole.x) + (GOPHER.Y-HOLE.Y) * (GOPHER.Y-HOLE.Y));  
} Char str[100];  
        int main () {while (~scanf ("%lf%lf%lf%lf\n", &gopher.x,&gopher.y,&dog.x,&dog.y)) {  
        int flag = 1;  
        Double Todog,togop;  
            while (gets (str)) {if (strlen (str) ==0) break;  
            SSCANF (str, "%LF%LF", &hole.x,&hole.y);  
            Dist (HOLE,TODOG,TOGOP); if (flag && Togop < Todog *0.5) {printF ("The Gopher can escape through the hole at (%.3LF,%.3LF). \ n", hole.x,hole.y);  
            Flag = 0;  
    } if (flag) puts ("The Gopher cannot escape.");  
return 0;   }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.