玩橡皮泥
两球揉成正方体,棱长去尾得 16
正文
// 原题:https://oj.yecheng.tv/p/1343
// 题意:两个球(半径 4 和 10)揉成正方体,求棱长(舍去小数取整)。
// 思路:总体积 V = 4/3*PI*(r1^3+r2^3),棱长 = floor(cbrt(V)),PI=3.141593。
// 复杂度:O(1)。
// 易错点:先求和体积再开三次方;结果要去尾取整不是四舍五入,加微小 eps 防止浮点误差。
#include <iostream>
#include <cmath>
using namespace std;
int main() {
const double pi = 3.141593;
double v = 4.0 / 3.0 * pi * (64 + 1000);
int edge = (int)floor(pow(v, 1.0 / 3.0) + 1e-9);
cout << edge << endl;
return 0;
}