UVA 12905 Volume of Revolution (几何,微积分)
2024-09-07 18:32:53
题意:分段用椎台面积近似计算体积,然后计算出近似值和真实值的相对误差
微积分加数学。
平头椎台的体积计算公式:
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 ;
}
最新文章
- java 命令notes
- Android使用Drawable资源之使用ClipDrawable资源 实现进入条
- 6.nodejs权威指南--进程
- Java-httpClient警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
- linux 查看僵尸进程
- 字符串反转(charat)
- Why Python is Slow
- Hibernate常见面试题
- 8.21 usaco
- iOS --- 取整数
- PHP发送POST请求的三种方式
- mysql HA方案: MHA
- 如何延长IntelliJ IDEA的试用期?
- C# TreeView设置SelectedNode设置无效的问题
- 前端笔记之NodeJS(四)MongoDB数据库&;Mongoose&;自制接口&;MVC架构思想|实战
- jenkins系列之插件配置(二)
- Optaplanner - 从探究示例中的hello world,初步认识规划引擎的运行步骤。
- 记号一下selenium+Firefox自动下载的参数
- 项目开发版本控制----Git
- codeforces 797B