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;  
    }  


  • 相关阅读:
    第七章之main函数和启动例程
    第一章之系统调用、库函数、内核函数区别
    unp第七章补充之socket tcp 产生 rst响应的情况
    unp第七章补充之TCP半开连接与半闭连接
    Qt 布局管理器
    Qt setMargin()和setSpacing() 的含义
    工作感悟
    关于数组数据常用的技巧
    正则表达式练习
    call/apply应用-对象使用原型链上的方法
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989548.html
Copyright © 2011-2022 走看看