This puzzle is a simplified version of the hard puzzle "Skynet : the bridge". The aim is to drive a motorbike to make it jump over a gap at the right speed and time. Validation tests are specific cases, that can be passed by implementing the algorithm given in the problem statement. Accelerate until you have enough speed to cross the gap, keep that speed until its time to jump and brake after the gap.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv)
{
int before, gap, after;
scanf("%d%d%d\n", &before, &gap, &after);
for (;;) {
// x = motorbike abscissa ; dx = motorbike speed
int dx, x;
scanf("%d%d", &dx, &x);
// if the bike has passed the gap, or going faster than needed to jump over it
if (x >= before+gap || dx > gap+1)
printf("SLOW\n");
// if the bike isn't going fast enough to jump over the gap
else if (dx <= gap)
printf("SPEED\n");
// if the bike can land after the gap by jumping
else if (x+dx >= before+gap)
printf("JUMP\n");
else
printf("WAIT\n");
}
return EXIT_SUCCESS;
}
import java.util.*;
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int before = in.nextInt();
int gap = in.nextInt();
int after = in.nextInt();
while (true) {
// x = motorbike abscissa ; dx = motorbike speed
int dx = in.nextInt();
int x = in.nextInt();
// if the bike isn't going fast enough to jump over the gap
if ((x >= before + gap) || (dx > gap + 1))
System.out.println("SLOW");
// if the bike is going slower than needed : speed
else if (dx <= gap)
System.out.println("SPEED");
// if the bike can land after the gap : jump
else if (x + dx >= before + gap)
System.out.println("JUMP");
else
System.out.println("WAIT");
}
}
}
before, gap, after = int(input()), int(input()), int(input())
while 1:
# x = motorbike abscissa ; dx = motorbike speed
dx, x = int(input()), int(input())
# if the bike is after the gap, or going faster than needed : slow
if (x >= before + gap) or (dx > gap+1):
print("SLOW")
# if the bike isn't going fast enough to jump over the gap
elif (dx <= gap):
print("SPEED")
# if the bike can land after the gap by jumping
elif (x+dx >= before+gap):
print("JUMP")
else:
print("WAIT")