X에서 Y보다 크거나 같은 곳으로 점프하고 싶다. 한번에 D만큼 점프할 수 있다고 했을 때, Y보다 크거나 같은 좌표에 도달할 수 있는 최소 점프 횟수를 구하라.
X + a*D >= Y
a*D >= Y-X
a >= (Y-X)/D
따라서 a는 (Y-X)/D를 올림한 값이다.
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int X, int Y, int D) {
// write your code in Java SE 8
return (int) Math.ceil((double) (Y-X) / D );
}
}
Math.ceil()
: 올림Math.round()
: 반올림Math.floor()
: 버림