BOJ

[백준온라인저지/BOJ] 2869번 달팽이는 올라가고 싶다

torimuk 2022. 1. 25. 14:51

문제


 

풀이


낮에는 A미터를 올라가고, 밤에는 B미터를 미끄러지므로, 하루에 올라가는 높이는 A-B 미터이다.

단, 정상에 도달할 경우엔 미끄러지지 않으므로 올라가야할 총 높이는 V-B 미터라고 할 수 있다.

따라서 총 높이/하루당 올라가는 높이 를 구해 올림처리 해주면 며칠이 걸리는 지 알 수 있다.

 


코드로 구현하면 다음과 같다.

import java.util.Scanner;
public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int A,B,V, day;
        double totalMoveMeter, dayPerMove;
        A = scanner.nextInt();
        B = scanner.nextInt();
        V = scanner.nextInt();

        totalMoveMeter = V - B;
        dayPerMove = A - B;
        day = (int) Math.ceil(totalMoveMeter/dayPerMove);
        System.out.println(day);
    }
}