Codeforces Round #327 (Div. 2)A. Wizards' Duel
2016-05-29 12:13
573 查看
A. Wizards' Duel
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
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 meters
per second, and the impulse of You-Know-Who's magic spell flies at a speed of 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.
Input
The first line of the input contains a single integer l (1 ≤ l ≤ 1 000) —
the length of the corridor where the fight takes place.
The second line contains integer p, the third line contains integer q (1 ≤ p, q ≤ 500) —
the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
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 10 - 4.
Namely: let's assume that your answer equals a, and the answer of the jury is b.
The checker program will consider your answer correct if
.
Examples
input
output
input
output
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.
题意:
给定路程l,a每秒的速度p,b每秒的速度q。求两人相遇后a走了多远。
思路:
先用m=l/(q+p)求出两人相遇的时间,然后求m*p求出a走了多远。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double l,q,p;
scanf("%lf%lf%lf",&l,&q,&p);
printf("%.4lf\n",l/(q+p)*q);
return 0;
}
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
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 meters
per second, and the impulse of You-Know-Who's magic spell flies at a speed of 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.
Input
The first line of the input contains a single integer l (1 ≤ l ≤ 1 000) —
the length of the corridor where the fight takes place.
The second line contains integer p, the third line contains integer q (1 ≤ p, q ≤ 500) —
the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
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 10 - 4.
Namely: let's assume that your answer equals a, and the answer of the jury is b.
The checker program will consider your answer correct if
.
Examples
input
100 50 50
output
50
input
199 60 40
output
119.4
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.
题意:
给定路程l,a每秒的速度p,b每秒的速度q。求两人相遇后a走了多远。
思路:
先用m=l/(q+p)求出两人相遇的时间,然后求m*p求出a走了多远。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double l,q,p;
scanf("%lf%lf%lf",&l,&q,&p);
printf("%.4lf\n",l/(q+p)*q);
return 0;
}
相关文章推荐
- CodeForces 3D Least Cost Bracket Sequence (贪心+优先队列)
- 随笔—邀请赛前训—Wizards' Duel
- UIButton的圆角
- 1369 - Answering Queries
- Android酷炫实用的开源框架(UI框架)
- Android UI(Layouts)-LinearLayout 详解
- UIVIew实战
- UIView
- UIResponder
- Leetcode 232. Implement Queue using Stacks
- HTML DOM querySelector() 方法
- QuickHit
- Hdu-5301 Buildings(思维题)
- UIDynamic介绍
- Android购物车初步实现1(UI篇)
- Android异步消息处理之Looper,Handler,Message,MessageQueue
- 设置tableView固定位置和尺寸---automaticallyAdjustsScrollViewInsets
- "\\ndk-build.cmd" clean Cannot run program "\ndk-build.cmd": Launching failed解决方法
- 2016 UESTC Traing Search Algorithm &String Problem N 简单的双向搜索
- [疯狂Java]集合:Deque(双端队列)以及两个实现(ArrayDeque、LinkedList)、Stack(摒弃)、各线性表性能分析