24h購物| | PChome| 登入
2012-05-13 11:54:18| 人氣1,584| 回應0 | 上一篇 | 下一篇

[UVA][Math] 10310 - Dog and Gopher

推薦 0 收藏 0 轉貼0 訂閱站台

Problem K

Dog and Gopher

Input: standardinput

Output: standardoutput

Time Limit: 1 second

Memory Limit: 32 MB

 

A large field has a gopher and adog. The dog wants to eat the gopher, while the gopher wants to run to safetythrough 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 gopherhole and heads for that hole in a straight line at a fixed speed. The dog, whichis very good at reading body language, anticipates which hole the gopher haschosen, and heads at double the speed of the gopher to the hole, where itintends to gobble up the gopher. If the dog reaches the hole first, the gophergets gobbled; otherwise, the gopher escapes.

You have to select a hole for the gopher throughwhich it can escape, if such a hole exists.

Input

The input file contains several sets of input.The first line of each set contains one integer and four floating pointnumbers. The integer n denotes howmany holes are in the set and the four floating point numbers denote the (x,y) coordinates of the gopherfollowed by the (x,y) coordinates ofthe dog. Subsequent n lines of inputeach contain two floating point numbers: the (x, y) coordinates of a gopher hole. All distances are in meters;to the nearest mm. Input isterminated by end of file. There is a blank line between two consecutive sets.

Output

Your shouldoutput a single line for each set of input. For each set, if the gopher canescape the output line should read "Thegopher can escape through the hole at (x,y)." identifying the appropriatehole to the nearest mm. Otherwise the output line should read "The gopher cannot escape."If the gopher may escape through more than one hole, report the one thatappears first in the input. There are not more than 1000 gopher holes in a set of input and all coordinates are between-10000 and +10000.

Sample Input:

1 1.000 1.000 2.000 2.000
1.500 1.500
 
2 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).

(Joint Effort Contest, Source: Waterloo ACM Programming Contest)

 #include <stdio.h>

int main() {
    int n;
    double x1,y1, x2, y2;
    while(scanf("%d %lf %lf %lf %lf", &n, &x1, &y1, &x2, &y2) == 5) {
        int find = 0;
        double x, y, ansx, ansy;
        while(n--) {
            scanf("%lf %lf", &x, &y);
            if(find)
                continue;
            if(4*((x1-x)*(x1-x)+(y1-y)*(y1-y)) <= (x2-x)*(x2-x)+(y2-y)*(y2-y)) {
                find = 1;
                ansx = x;
                ansy = y;
            }
        }
        if(find) {
            printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n", ansx, ansy);
        } else {
            puts("The gopher cannot escape.");
        }
    }
    return 0;
}

台長: Morris
人氣(1,584) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][外心座標] 190 - Circle Through Three Points
此分類上一篇:[UVA][二分圖最大匹配] 10080 - Gopher II

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文