Fading Wind
Time limit1sMemory limit1024 MB
Simulate a paper airplane's height and velocity under a fading wind and output the total horizontal distance it travels.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
You are competing in an outdoor paper airplane flying contest, and you want to predict how far your paper airplane will fly. Your design has a fixed factor . If the airplane's velocity is at least , it rises. If its velocity is less than , it descends.
Here is how your paper airplane flies:
-
You start by throwing the airplane with a horizontal velocity of at a height of . An external wind blows with a strength of .
-
While , repeat the following sequence:
- Increase by . Then, decrease by . Here is rounded down to the nearest integer.
- If , increase by one.
- If , decrease by one. If is zero after the decrease, set to zero.
- If , set to zero and to zero.
- The airplane now travels horizontally by units.
- If , decrease by .
Compute how far the paper airplane travels horizontally.
Input
The single line of input contains four integers , , , and , where is the starting height, is the fixed factor, is the starting velocity, and is the strength of the wind.
Output
Output a single integer, the horizontal distance the airplane travels. The distance is always an integer.