5 solutions

  • -2
    @ 2025-3-31 14:10:22

    import java.util.Scanner;

    public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //定义变量接受要游的距离
        double distance = sc.nextDouble();
    
        //定义变量接受要游的步数,还有步幅
        int steps = 0;
        double stepLength = 2;
    
        //用while循环来计算步数
        while (distance > 0) {
            distance -= stepLength;
            steps++;
            stepLength *= 0.98;
        }
    
        //输出步数
        System.out.println(steps);
    }
    

    }

    Information

    ID
    5481
    Time
    1000ms
    Memory
    125MiB
    Difficulty
    1
    Tags
    (None)
    # Submissions
    589
    Accepted
    331
    Uploaded By