JC15A - Windy Cannon
Windy Cannon
This day is very windy, the wind blow very fast that it may be faster than the speed of cannon ball. On this windy day, Gunawan want to test his new prototype cannon, he want to shoot the target at specific location. But before doing that, he wonder how long it take for the cannon ball to hit the target. He know percisely the position of his cannon, the location of the target, the speed of his cannon ball, the speed of wind blows, and the direction of the wind, but unfortunately he forgot to bring the calculator so he ask you for help to calculate the minimum time needed for the cannon ball to hit the target or specify if it's impossible. Can you help him? You can assume that the speed of cannon ball relative to the wind is constant, all other physical effect such as gravity, air friction, temperature, magnus effect are ignored.
Input
The first line there are 4 integers and 1 character CP, TP, CBS, WS, WD denoting cannon position (m), target position (m), cannon ball speed (m/s), wind speed (m/s), and wind direction respectively.
Output
Print how many seconds the minimum time needed for cannon ball to hit the target rounded to 6 digits after decimal point.
If it's impossible for the cannon ball to hit the target, print "Impossible" without quotes.
Constraint
0 ≤ CP ≤ 100
0 ≤ TP ≤ 100
0 ≤ CBS ≤ 100
0 ≤ WS ≤ 100
if WD = 'L', it means that the wind blow into negative direction (left in catesian plane).
if WD = 'R' it means that the wind blow into positive direction (right in cartesian plane).
Sample 1
Input
2 10 2 1 L
Output
8.000000
Sample 2
Input
2 10 2 1 R
Output
2.666667
Sample 3
Input
2 10 2 3 L
Output
Impossible
Sample 4
Input
10 2 2 3 L
Output
1.600000
Sample 5
Input
50 50 12 34 R
Output
0.000000
Sample 4 Explanation
The cannon ball move at speed 2 m/s relative to the wind, so if it shoot to the right, because of the wind blowing 3 m/s to the left relative to the ground, the cannon ball move (3-2=1) m/s to the left relative to the ground and will eventually hit the target in 8 seconds, but this is not optimal, it's faster to shoot the cannon ball to the left, because the wind blowing 3 m/s to the left relative to the ground (and the same direction as the cannon ball move relative to the wind), so the cannon ball will move (3+2=5) m/s to the left relative to the ground and will eventually hit the target at (10-2)/5 = 8/5 = 1.6 seconds. We need to print the result rounded to 6 digit after decimal places, so the minimum time needed for the cannon ball to reach the target is 1.600000 seconds.
hide comments
lalit_nit:
2016-02-16 16:26:24
In first shot...Feeling confident After Solving #Tjandra Problem :P....... |
|
better_clever:
2016-02-02 00:53:50
@author not able to figure out in which case I am getting wrong answer. Any hints!! ?
|
|
(Tjandra Satria Gunawan)(曾毅昆):
2016-01-31 20:28:18
@queen_123: just delete line containing "while(1)" and you'll not getting TLE anymore, the input file containing only single case.
|
|
queen_123:
2016-01-31 10:13:11
hey gunawan .....can u plz check my submission why i'm getting tle in test case 0 |
Added by: | Tjandra Satria Gunawan |
Date: | 2016-01-18 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |
Resource: | Own Problem, used in Jolly Challenge #15 |