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

微积分加数学。

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

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 ;
}

最新文章

  1. java 命令notes
  2. Android使用Drawable资源之使用ClipDrawable资源 实现进入条
  3. 6.nodejs权威指南--进程
  4. Java-httpClient警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
  5. linux 查看僵尸进程
  6. 字符串反转(charat)
  7. Why Python is Slow
  8. Hibernate常见面试题
  9. 8.21 usaco
  10. iOS --- 取整数
  11. PHP发送POST请求的三种方式
  12. mysql HA方案: MHA
  13. 如何延长IntelliJ IDEA的试用期?
  14. C# TreeView设置SelectedNode设置无效的问题
  15. 前端笔记之NodeJS(四)MongoDB数据库&amp;Mongoose&amp;自制接口&amp;MVC架构思想|实战
  16. jenkins系列之插件配置(二)
  17. Optaplanner - 从探究示例中的hello world,初步认识规划引擎的运行步骤。
  18. 记号一下selenium+Firefox自动下载的参数
  19. 项目开发版本控制----Git
  20. codeforces 797B

热门文章

  1. 13. linux渗透之反弹shell
  2. Protobuf 文件生成工具 Prototool 命令详解
  3. HDU - 1171 Big Event in HDU 多重背包
  4. Ubuntu 16 Mysql 安装配置
  5. Unity开发Android应用优化指南(上)
  6. 51nod1113(矩阵快速幂模板)
  7. uoj#348/洛谷P4221 [WC2018]州区划分(FWT)
  8. 洛谷P3704 [SDOI2017]数字表格(莫比乌斯反演)
  9. Java 基础类库
  10. 页面出现滚动条时,body里面的内容不能自动居中?