zoukankan      html  css  js  c++  java
  • ZOJ 1860:Dog & Gopher

    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 surface 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 that 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 the speed of the gopher to the hole, where it intends to gobble up the gopher. If the dog reaches the hole first, the gopher gets gobbled; otherwise, the gopher escapes.

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


    Input

    The first line of input contains four floating point numbers: the (x,y) coordinates of the gopher followed by the (x,y) coordinates of the dog. Subsequent lines of input each contain two floating point numbers: the (x,y) coordinates of a gopher hole. All distances are in 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 of a single line. If the gopher can escape the line should read "The gopher can escape through the hole at (x,y)." identifying the appropriate 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 first 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

    迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

    #include<iostream>  
    #include<cstdio>  
    #include<sstream>  
    #include<algorithm>  
    #include<cstring>  
    #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-hole.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
    ",&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).
    ",hole.x,hole.y);  
                    flag = 0;  
                }  
            }  
            if(flag)puts("The gopher cannot escape.");  
        }  
        return 0;  
    }  


  • 相关阅读:
    HTML5学习笔记简明版(1):HTML5介绍与语法
    用margin还是用padding(1)——W3School CSS外边距合并
    Minimum Depth of Binary Tree
    118. Pascal's Triangle
    Convert Sorted Array to Binary Search Tree
    112. Path Sum
    Balanced Binary Tree
    centos 7下nginx搭建流媒体服务器【动态添加模块】
    Java内存泄漏
    Quartz的job中注入的services接口为空的解决办法
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989548.html
Copyright © 2011-2022 走看看