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)\n", 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\n", sx, sy) ;
33     }
34     if (!flag) printf ("Firefly %d not caught\n", 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值