HUST 1360 Solve the integration 自适应simpson积分模板题
来源:互联网 发布:孙叔敖之知翻译 编辑:程序博客网 时间:2024/06/18 15:25
1360 - Solve the integration
Time Limit: 1s Memory Limit: 256MB
Submissions: 203 Solved: 53
- Description
- Wincat is a clever boy, he has just had a math class and has just learned about Integration, and just think is too easy to learn. Then he say to He’s math teacher Peter “it is too easy for me, could your give more hard lesson?” say with Disdain.”Ok, If you can solve this problem I give to your ,then I will teach your more hard lesson”. Then Peter turn around to the blackboard and write down a Equation like below:
Wincat is confused by this question, you are one of good friend of him ,could your help him? - Input
- The input contains multiple test cases, each case give you a float number x (0.0<=x<=100.0) .
- Output
- Output the result of that equation, Round the numbers in the output to 4 digits after decimal point.
- Sample Input
0.2
- Sample Output
0.0200
- Hint
- Source
- 中国地质大学(武汉)第七届ACM程序设计大赛暨华中地区部属高校ACM邀请赛
训练时发现自己根本解不出来这个积分(数学渣渣QAQ)。赛后才知道这题可以用模板去做。。。那么以后碰到这样的题就方便多了。
simpson模板:
模板理解:a和b分别代表所求积分的上下限。eps的值一般为 : 1e-6
同时还要加上一个函数double F(double x);这个函数就是你要求的函数
上代码:
#include<cstdio>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>using namespace std;const double eps=1e-6;///eps的值double F(double t){ return t/sqrt(t*t*t + 1.0);///对应题目所需求解的方程}double simpson(double a,double b){ double c=a+(b-a)/2; return (F(a) +4*F(c)+F(b))*(b-a)/6;}double asr(double a,double b,double eps, double A){ double c=a+(b-a)/2; double L=simpson(a,c),R=simpson(c,b); if(fabs(L+R-A) <= 15*eps ) return L+R+(L+R-A)/15.0; return asr(a,c,eps/2,L) + asr(c,b,eps/2,R);}double asr(double a,double b,double eps){ return asr(a,b,eps,simpson(a,b));}int main(){ double x; while(cin>>x) { printf("%.4lf\n",asr(0,x,eps));///传入上下限和eps } return 0;}
可以分为几个部分来看
1: F()函数部分
double F(double t){ return t/sqrt(t*t*t + 1.0);///对应题目所需求解的方程}
2:模板部分
double simpson(double a,double b){ double c=a+(b-a)/2; return (F(a) +4*F(c)+F(b))*(b-a)/6;}double asr(double a,double b,double eps, double A){ double c=a+(b-a)/2; double L=simpson(a,c),R=simpson(c,b); if(fabs(L+R-A) <= 15*eps ) return L+R+(L+R-A)/15.0; return asr(a,c,eps/2,L) + asr(c,b,eps/2,R);}double asr(double a,double b,double eps){ return asr(a,b,eps,simpson(a,b));}虽说是套了模板,但是还是要努力理解啊QAQ
0 0
- HUST 1360 Solve the integration 自适应simpson积分模板题
- hdu 1724 Ellipse(自适应Simpson积分) (模板)
- 自适应simpson积分
- 自适应Simpson积分
- 自适应simpson 积分
- 邝斌的ACM模板(自适应 simpson 积分)
- 学习笔记: 自适应Simpson积分
- 自适应Simpson积分(近似求积分)
- [SPOJ CIRU]The area of the union of circles(自适应Simpson积分求圆并面积)
- hdu 1724 自适应 simpson 算法 求积分
- 自适应simpson公式解定积分
- hdoj-1724 Ellipse(自适应Simpson积分)
- HDOJ-4498 Function Curve(自适应Simpson积分)
- CSU 1806 Toll(自适应simpson积分)
- CSU 1806 Toll (自适应Simpson积分 )
- HDU 1724 Ellipse 【自适应Simpson积分】
- HDOJ 1724 Ellipse(自适应simpson积分)
- 【HDU1724】Ellipse-自适应Simpson积分法
- Easy-36
- EasyUI修改datetimebox 时间选择框 加'清空'按钮 修改'今天 '事件
- Redis常用配置详解redis.conf
- 死锁,银行家算法
- Google Hacking
- HUST 1360 Solve the integration 自适应simpson积分模板题
- Android、IOS 图片上传接口(Java实现Servlet)
- Java 各种概念总结--持续更新中
- angular.js学习笔记
- tensorflow模块因缺少库加载不成功
- 如何在Java中导入Excel表数据
- 循环神经网络
- android activity的关闭处理的几种方式
- stm32 F407串口通信出现乱码