CodeForces 591 A. Wizards Duel 简单题

1. 题目描述

1.1. Limit

Time Limit: 2 seconds

Memory Limit: 256 MB

1.2. Problem Description

Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length l l . Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry’s magic spell flies at a speed of p p meters per second, and the impulse of You-Know-Who’s magic spell flies at a speed of q q meters per second.

The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it’s caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.

Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn’t good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.

1.3. Input

The first line of the input contains a single integer l l ( 1 l 1 000 1 ≤ l ≤ 1 000 ) — the length of the corridor where the fight takes place.

The second line contains integer p p , the third line contains integer q q ( 1 p , q 500 1 ≤ p, q ≤ 500 ) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.

1.4. Output

Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 1 0 4 10^{-4} .

Namely: let’s assume that your answer equals a a , and the answer of the jury is b b . The checker program will consider your answer correct if a b max ( 1 , b ) 1 0 4 \frac{|a - b|}{\max(1, b)} \le 10^{-4} .

1.5. Sample Input

100

1.6. Sample Output

50

1.7. Note

In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.

1.8. Source

CodeForces 591 A. Wizards’ Duel

2. 解读

A A B B 距离 l l 米,小球 k 1 k_1 A A 出发以速度 p p B B 运动, k 2 k_2 B B 出发以速度 q q A A 运动,两小球相撞后以原有速度往反方向运动,回到出发点后再以原有速度往反方向运动。求两小球第二次相撞的地点到 A A 的距离。

求第一次相撞地点即可,结果为

l ( p + q ) × p \frac{l}{(p + q)} \times p

保留 5 5 位小数。

3. 代码

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    double l, p, q;
    scanf("%lf %lf %lf", &l, &p, &q);
    double ans = l / (p + q) * p;
    printf("%.5lf", ans);
    return 0;
}

联系邮箱[email protected]

CSDNhttps://me.csdn.net/qq_41729780

知乎https://zhuanlan.zhihu.com/c_1225417532351741952

公众号复杂网络与机器学习

欢迎关注/转载,有问题欢迎通过邮箱交流。

猜你喜欢

转载自blog.csdn.net/qq_41729780/article/details/106515777