hdu 2701

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2701

题意:你有一双可以瞬移的鞋子,任务是要捕捉一直可以瞬移的萤火虫。给出自己每次瞬移的最远距离和起始坐标,再依次给出这只萤火虫出现的坐标。每次虫子出现,你都向它的坐标瞬移。一旦你和虫的距离不超过1,则认为捕捉到。问虫子在哪个坐标被捕捉到(或不能被捕捉到)。

mark:阅读题。阅读了好久,题目又臭又长,只要明白了题意很容易1A。。。

代码:

 1 # include <stdio.h>
 2 # include <math.h>
 3 
 4 
 5 int r, x, y ;
 6 
 7 
 8 double dist(double ax, double ay, double bx, double by)
 9 {
10     return sqrt((ax-bx)*(ax-bx) + (ay-by)*(ay-by)) ;
11 }
12 
13 
14 void work(int cas)
15 {
16     double sx = x, sy = y, ex, ey, t ;
17     int flag = 0 ;
18     while (1)
19     {
20         scanf ("%lf%lf", &ex, &ey) ;
21         if (ex < 0 && ey < 0) break ;
22         if (flag) continue ;
23         if (dist(sx, sy, ex, ey) <= r+1.0)
24         {
25             printf ("Firefly %d caught at (%.0lf,%.0lf)
", cas, ex, ey) ;
26             flag = 1 ;
27             //return ;
28         }
29         t = r*1.0 / dist(sx, sy, ex, ey) ;
30         sx = sx + (ex-sx)*t ;
31         sy = sy + (ey-sy)*t ;
32     //    printf ("%lf, %lf
", sx, sy) ;
33     }
34     if (!flag) printf ("Firefly %d not caught
", cas) ;
35 }
36 
37 
38 int main ()
39 {
40     int nCase = 1 ;
41     while (scanf ("%d%d%d", &r, &x, &y) && (r||x||y))
42         work(nCase++) ;
43     return 0 ;
44 }
原文地址:https://www.cnblogs.com/lzsz1212/p/3299769.html