HUD2701Lampyridae Teleportae

本文介绍了一种使用特殊瞬移鞋捕捉能够瞬移的萤火虫(Lampyridae Teleportae)的策略。玩家需根据萤火虫每次瞬移后的精确位置,通过一次瞬移接近并尝试捕捉。文章详细解释了游戏规则,包括如何计算瞬移距离及如何判断是否成功捕捉。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
The discovery of a remarkable new insect, the Lampyridae Teleportae, more commonly known as the teleporting firefly, has sparked a no-less-remarkable number of ways to try to catch them. Rather than flying, the Lampyridae Teleportae teleports from spot to spot by warping space-time. When it stops between teleports, it hovers for a moment and flashes its light in search of a mate. So, even though they only come out after dark, it’s easy to observe them, but very difficult to catch them. Fortunately for the Association for Catching Lampyridae (ACL), student members of the Association for Cool Machinery (ACM) recently developed the world’s first teleporting tennis shoes. The tennis shoes are efficient enough that, when a
Lampyridae Teleportae is spotted by its flash, there is always time to teleport once before the firefly itself teleports off to another location, but there is never time to teleport twice in a row before the firefly teleports away. The tennis shoes have a maximum teleport range, however, depending on how well their flux capacitor is constructed, so it’s not always possible to catch a Lampyridae Teleportae with just a single teleport. The
most efficient catching method is to remain in place until a firefly flashes, and to then teleport in a straight line directly toward it, subject to the limitation of the maximum range of ones tennis shoes, in an attempt to get close enough to catch it. If you don’t get close enough, you wait for the next flash, teleport towards it again, and repeat, until you either catch it or it’s gone.
For this programming problem you will simulate this procedure for catching teleporting fireflies with a few simplifying assumptions:
(1) We will be chasing only one firefly at a time.
(2) Firefly chasing will take place in two dimensions where all units are considered to be yards.
(3) The firefly is “caught” if the chaser can manage to come within one yard of the firefly.
(4) The chaser’s movement toward a firefly is always in a straight line from his or her current location directly toward the flash; if the range of the chaser’s tennis shoes prevents getting close enough to catch the firefly, the chaser will always teleport the maximum range possible (thus, although the chaser always starts at integer coordinates, it is possible and likely that any or all of the chaser’s locations after the first teleport will be at non-integer coordinates).
The input will consist of several chase scenarios. For each scenario you will be given the maximum range in yards of the chaser’s teleporting tennis shoes, the chaser’s starting location, and a list of one or more flash
locations for the firefly being chased. For each chase scenario your program will output a single line indicating either the flash location where the firefly was caught, or a message noting that the firefly was never caught.

Input
The first line of a chase scenario contains three numbers, delimited by a single space, in the following order: the maximum range in yards of the chaser’s teleporting tennis shoes, the starting x-coordinate of the chaser, and the starting y-coordinate of the chaser. The maximum range will be a positive integer from 1 to 1000. The x and y values for the starting coordinates will be integers from 0 to 1000. The remaining lines of
an input scenario contain two integers each, an x-coordinate and a y-coordinate, again delimited by a single space. These are, in order of appearance, the locations where the firefly flashes. All coordinate values range from 0 to 1000. A line specifying a value of -1 for both x and y terminates the list, at which point we consider the firefly to disappear never to be seen again. Note that a firefly might be caught at a flash location prior to end of the list; in this case the rest of the flash locations listed in the input for the current chase scenario should simply be ignored.
The next input scenario begins on the line immediately after the last line of the preceding scenario. An input scenario that specifies 0 (zero) as the maximum range of the chaser will terminate the input.

Output
Every output line will be either:
(1) “Firefly N caught at (x,y)”, where N is the input scenario number starting with 1, and (x,y) is the last location the firefly flashed before it was caught; or
(2) “Firefly N not caught”.

Sample Input
2 0 0
3 3
4 4
5 5
6 6
7 7
-1 -1
2 0 0
3 3
5 5
7 7
-1 -1
10 50 50
50 62
40 55
30 55
45 45
50 50
55 55
50 50
-1 -1
0 0 0

Sample Output
Firefly 1 caught at (6,6)
Firefly 2 not caught
Firefly 3 caught at (50,50)

Source
2008 Mid-Central USA

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

#include<iostream>
#include<math.h>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int Inf=100000;
double dis(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
    int k,x,y,cas=1;
    while(cin>>k>>x>>y){
        double xx=x*1.0,yy=y*1.0;//注意题目说距离在第一次之后就有可能是非整数了
        if(k==0&&x==0&&y==0)
            break;
        else{
            double a,b,t;
            int i,p=-1;
            for(i=0;;i++){
                cin>>a>>b;
                if(a<0&&b<0)
                    break;
                else{
                    if(p==1)
                        continue;
                    if(dis(xx,yy,a,b)<=k+1.0){
                        p=1;
                        printf ("Firefly %d caught at (%.0lf,%.0lf)\n",cas++,a,b);
                    }
                    t=k*1.0/dis(xx,yy,a,b); 
                    xx+=(a-xx)*t;
                    yy+=(b-yy)*t;
                    //记算坐标的方法可以有多种吧,没实验过,有好主意的欢迎留言讨论啦
                }
            }
            if (p==-1) 
                printf ("Firefly %d not caught\n",cas++);
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值