[Java] a686. 蝸牛往上爬

要注意的: 不是下滑速度大於上爬速度就一定無法到達目的地

import java.io.BufferedInputStream;
import java.util.Scanner;

public class A686 {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        int a = Integer.parseInt(in.nextLine());
        for(int i = 0; i < a; i++) {
            int distance = in.nextInt();
            int up = in.nextInt();
            int down = in.nextInt();
            if(down >= up && distance > up) {
                System.out.println("Poor Snail");
            }
            else {
                int day = 0;
                while(true) {
                    day++;
                    distance -= up;
                    if(distance <= 0) {
                        break;
                    }
                    distance += down;
                }
                System.out.println(day);
            }
        }
        in.close();
    }
}

沒有留言:

張貼留言