1 条题解

  • 0
    @ 2007-9-30 12:23:44

    【深基2.例3】玩橡皮泥

    解题思路

    两个球体积之和为 (4/3)π(4³+10³),揉成正方体后体积不变,棱长为总体积的立方根。

    正确性说明

    体积守恒给出棱长三次方等于两球体积和;取正立方根得到棱长,转整数舍去小数。

    易错点

    4/3 要写成 4.0/3;按题目给出的 π 取值。

    复杂度

    时间 O(1),空间 O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        double v = 4.0 / 3 * 3.141593 * (4 * 4 * 4 + 10 * 10 * 10);
        cout << int(cbrt(v)) << "\n";
        return 0;
    }
    
    • 1