top1编程
← 返回题目
题解

【基础】龟兔赛跑

1 条题解

  • 0
    @ 2026-7-29 0:15:35
    #include <iostream>
    using namespace std;
    
    int main() {
        int x, y, t;
        cin >> x >> y >> t;
    
        // 核心公式:d ≤ t*x*y/(y - x),取整数部分即为最大距离
        // 用整数运算避免浮点精度问题:先算乘法再算除法(因为t*x*y 能被 (y-x) 整除或取整)
        int max_distance = (t * x * y) / (y - x);
    
        cout << max_distance << endl;
    
        return 0;
    }
    
    • 1