FTHEELF - Feanor The Elf

no tags 

Feanor is an elf, and of course, he really likes arrows and bows. Surprisingly enough, Feanor has a laptop, but he knows nothing about programming, so he requires your help.

Feanor lives in a tower of height H, and he loves throwing arrows from the top of it. He had a good amount of intensive training and he knows that he always throws his arrows with the same initial speed V. He wants you to make a program that given H and V returns the maximum distance that a Feanor’s arrow can reach when it hits the ground, measured from the base of the tower. With this information, he will be able to place a nice circular fence to prevent disoriented little elves from being killed. Newtonian laws apply in Feanor’s world and the gravity has the same strength as in ours. These laws can be summarized as follows:

  • The position of Feanor is assumed to be a point. The same occurs with the position of his arrow at each moment in time.
  • The initial speed V of the arrow can be expressed as Vx2 + Vy2 = V2 , where Vx and Vy are the horizontal and vertical components of V , respectively. Speed Vx is always non- negative, while speed Vy is positive if the arrow is thrown up, and negative if the arrow is thrown down.
  • The initial position of the arrow is the position of Feanor.
  • The horizontal position of the arrow (relative to Feanor’s position) at time t is x(t) = Vx * t.
  • The vertical position of the arrow (relative to Feanor’s position) at time t is y(t) = Vy * t − gt2 / 2, where g = 9.8 m/s2.

Input

The input contains several test cases. Each test case is described in a single line that contains two integers V and H separated by a single space. The value V is the initial speed of Feanor’s arrow measured in m/s (0 ≤ V ≤ 1000), while the value H is the tower’s height in meters (0 ≤ H ≤ 1000). The last line of the input contains the number −1 twice separated by a single space and should not be processed as a test case.

Output

For each test case output a single line with the radius of Feanor’s fence in meters, rounded up to 6 decimal digits (he wants to be sure that he doesn’t kill those cute little elves).

Example

Input:
1 0
10 0
100 0
1000 0
-1 -1

Output:
0.102041
10.204082
1020.408163
102040.816327

hide comments
যোবায়ের: 2012-07-05 20:16:27

I can't believe this, using an eps of 1e-9 got me numerous WA :( Passed without using eps. This is insane!

saket diwakar: 2012-06-30 18:13:28

thanx @andy.i was stuck with that.
finally AC.:)

Andy: 2011-11-15 18:43:10

If keep getting WA, check answer for 0 0

Last edit: 2011-11-15 18:45:10
Tim Trewartha: 2011-10-03 22:52:02

Although the problem specification says round up to 6 decimal places, if you do this you get WA - in the end I just used the standard C++ rounding and it worked.

Santiago Palacio: 2011-06-16 03:10:05

How to i mprove presicion in C++? i'm sure i found the formula, but i keep getting WA.
EDIT: What would be the output for 0-1000?

Last edit: 2011-06-23 13:19:46
Bored: 2011-06-14 13:40:14

Double is enough to AC

Caesum: 2011-01-12 22:36:39

What is the output for 1000 1000 ? I get 103035.963766

:D: 2011-01-01 10:44:34

Always use long double.

.::Manish Kumar::.: 2011-01-01 09:02:29

LOL .. PRECISION PROBLEM ... NOT USEFUL

anurag: 2010-12-11 13:51:05

@shuaib akram : i had the same problem . it seems i was loosing precision somewhere. same algo in python got ac


Added by:Pablo Ariel Heiber
Date:2010-08-13
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 VB.NET
Resource:FCEyN UBA ICPC Selection 2007