Created
October 5, 2014 17:17
-
-
Save tai2/b66b0271705aeb689e60 to your computer and use it in GitHub Desktop.
http://www.codingame.com/puzzles Skynet: the Chasm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var R = parseInt(readline()) - 1; // the length of the road before the gap. | |
| var G = parseInt(readline()); // the length of the gap. | |
| var L = parseInt(readline()); // the length of the landing platform. | |
| var S, X; | |
| var t = 0; | |
| var remaining, S_needed, t_accel, t_adjust; | |
| var initialized; | |
| function dist(S_initial, S_needed) { | |
| var d = 0, s; | |
| if (S_initial < S_needed) { | |
| for (s = S_initial; s < S_needed; s++) { | |
| d += s + 1; | |
| } | |
| } else { | |
| for (s = S_initial; S_needed < s; s--) { | |
| d += s - 1; | |
| } | |
| } | |
| return d; | |
| } | |
| while (true) { | |
| S = parseInt(readline()); // the motorbike's speed. | |
| X = parseInt(readline()); // the position on the road of the motorbike. | |
| if (!initialized) { | |
| S_needed = G + 1; | |
| t_accel = Math.abs(S_needed - S); | |
| remaining = R - dist(S, S_needed); | |
| t_adjust = remaining % S_needed; | |
| initialized = true; | |
| } | |
| if (t < t_adjust) { | |
| print('WAIT'); | |
| } else if (t < t_accel + t_adjust) { | |
| if (S < S_needed) { | |
| print('SPEED'); | |
| } else if (S_needed < S) { | |
| print('SLOW'); | |
| } | |
| } else if (X < R) { | |
| print('WAIT'); | |
| } else if (X === R) { | |
| print('JUMP'); | |
| } else { | |
| print('SLOW'); | |
| } | |
| t++; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment