题意:一个正方形被四个半圆分成了3部分,给出正方形的边长,求每个部分的面积
数学题,看代码吧。
坑:double 的精度问题 用long double或者减少乘除运算
代码:
#include <cstdio>
#include <cmath>
const double PI = acos(-1.0);
const double GEN = sqrt(3.0);
using namespace std;
int main(void)
{
double s1 = (3.0 - 3.0*GEN + PI )/3.0;
double s2 = (PI + 6.0 *GEN- 12.0) / 3.0;
double s3 = (12.0 - 3.0*GEN - 2.0*PI) / 3.0;
double a;
while(scanf("%lf", &a) != EOF){
printf("%.6f %.6f %.6f\n",s1 * a * a, s2 * a * a, s3 * a * a);
}
return 0;
}
本文详细介绍了如何通过数学公式解决正方形被四个半圆分割成三部分的面积计算问题,并提供了相应的C++代码实现。文章特别注意到了double类型在计算中的精度问题,提出了使用longdouble或者减少乘除运算的解决方案。

115

被折叠的 条评论
为什么被折叠?



