UVA 12905 Volume of Revolution (几何,微积分)

题意:分段用椎台面积近似计算体积,然后计算出近似值和真实值的相对误差

微积分加数学。

平头椎台的体积计算公式:

V = 1/3*h*(S1+S2*sqrt(S1*S2)

一个更快的计算多项式值的方法: for(int i = 15; i >= 0; i--) ans = ans*x+p[i],比直接pow快了一倍

#include<cstdio>
#include<cmath>
#include<cstring>
const double pi = atan()*; int poly[],Q[],n; inline double calR(double x)
{
double ans = poly[];
for(int i = ; i <= n; i++ ){
ans += poly[i]*pow(x,i);
}
return ans;
} inline double calint(int x){
double ans = ;
for(int i = ,sz = n<<; i <= sz; i++ ){
ans += Q[i]*pow(x,i+)/(i+);
}
return ans;
} inline double calV(int a,int b){
memset(Q,,sizeof(Q));
for(int i = ; i <= n; i++){
for(int j = ; j <= n; j++)
Q[i+j] += poly[i]*poly[j];
} return (calint(b)-calint(a))*pi;
} inline double calS(double R,double theta,int slices){
return R*sin(theta)/*R*slices;
} int main()
{ int T;
scanf("%d",&T);
int cas = ;
while(T--){
memset(poly,,sizeof(poly));
scanf("%d",&n);
for(int i = n; i >= ;i--)
scanf("%d",poly+i);
int a,b;
scanf("%d%d",&a,&b);
int slices,stacks;
scanf("%d%d",&slices,&stacks);
double dx = (b-a)*1.0/stacks, dtheta = *pi/slices;
double R1 = calR(a),S1 = calS(R1,dtheta,slices); double x = a+dx; double ape = ;
for(int i = ; i < stacks; i++){
double R2 = calR(x);
double S2 = calS(R2,dtheta,slices);
double dS = dx/*(S1+S2+sqrt(S1*S2));
ape += dS;
x += dx;
R1 = R2; S1 =S2;
}
double vol = calV(a,b); printf("Case %d: %.4lf\n",++cas,fabs(ape-vol)/vol*);
}
return ;
}
上一篇:Android学习总结——Popup menu:弹出式菜单


下一篇:.NET导入导出Excel