1 条题解

  • 0
    @ 2024-12-15 14:04:26
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main() {
        int m, n, x, y, s;
        cin >> m >> n >> x >> y >> s;
    
        // 初始速度
        double speed = n - x - y;
        
        // 如果初始速度小于等于0,则李洋老师无法移动
        if (speed <= 0) {
            cout << "谢猪然,你变菜了" << endl;
            return 0;
        }
    
        // 将时间转换为小时,因为我们的速度是以km/h为单位的
        double totalHours = 0.0;
        double remainingDistance = s;
        double boostedSpeed = speed; // 用于存储加速后的速度
    
        // 循环计算所需时间,直到剩余距离小于等于0
        while (remainingDistance > 0) {
            // 计算在当前速度下走完10km所需的时间(如果剩余距离小于10km,则走完剩余距离)
            double distanceToCover = min(10.0, remainingDistance);
            double timeForDistance = distanceToCover / speed;
            totalHours += timeForDistance;
            remainingDistance -= distanceToCover;
    
            // 如果走完了10km,则速度增加n倍(只针对接下来的1km)
            if (distanceToCover == 10.0) {
                boostedSpeed = speed * n;
                // 但我们只需要用这个加速速度走1km,所以更新剩余距离和总时间
                if (remainingDistance > 1) {
                    timeForDistance = 1.0 / boostedSpeed;
                    totalHours += timeForDistance;
                    remainingDistance -= 1;
                } else {
                    // 如果剩余距离小于或等于1km,则直接用加速速度走完
                    totalHours += remainingDistance / boostedSpeed;
                    remainingDistance = 0;
                }
                // 恢复到正常速度
                speed = n - x - y;
            }
        }
    
        // 判断总时间是否小于等于给定的时间m
        if (totalHours <= m) {
            cout << "谢猪然,你变强了" << endl;
        } else {
            cout << "谢猪然,你变菜了" << endl;
        }
    
        return 0;
    }
    
    
    • 1

    信息

    ID
    3
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    (无)
    递交数
    2
    已通过
    1
    上传者