题目大意
有一个瓶子,是由一条曲线绕着
x
轴旋转得到的。瓶底的直线为
解答
V=∫XhighXlowf(x)2×dx≈Xhigh−Xlow6[f(Xlow)2+4f(Xlow+Xhigh2)2+f(Xhigh)2]
由此可以用辛普森自适应公式算出所有需要的体积。
接着进行二分答案,查找每个等体积线的 x <script id="MathJax-Element-29" type="math/tex">x</script>坐标。依次解出即可。
参考代码
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 0.0001;
int n;
double a[15];
double xl, xh;
double inc;
double f(double x)
{
double ans = 0;
double xx = 1;
for (int i = 0; i <= n; i++) {
ans += a[i]*xx;
xx *= x;
}
return ans*ans;
}
double simpon(double a, double b)
{
return (b-a)/6.0*(f(a)+4*f((a+b)/2)+f(b));
}
double work(double a, double b)
{
double cmp = simpon(a, (a+b)/2)+simpon((a+b)/2, b);
double cmp1 = simpon(a, b);
if (fabs(cmp-cmp1) < eps)
return cmp;
return work(a, (a+b)/2) + work((a+b)/2, b);
}
void readin()
{
scanf("%d", &n);
for (int i = 0; i <= n; i++)
scanf("%lf", &a[i]);
scanf("%lf %lf %lf", &xl, &xh, &inc);
}
void find(double now)
{
double l = xl, h = xh;
double m;
double tmp;
while (true) {
m = (l+h)/2;
tmp = work(xl, m)*3.1415926 - now;
if (fabs(tmp) < eps) {
printf("%.2lf ", m-xl);
return;
}
if (tmp < 0)
l = m;
else
h = m;
}
}
int main()
{
readin();
double v = work(xl, xh)*3.1415926;
printf("%.2lf\n", v);
if (v < inc) {
printf("insufficient volume");
}
for (double now = inc, i = 0; now <= v && i < 8; now += inc, i++) {
find(now);
}
return 0;
}