Acdream 1234 Two Cylinders(自适应辛普森积分法)
2016-06-26 19:11
309 查看
传送门
Two Cylinders
Special Judge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Submit Statistic Next Problem
Problem Description
Input
Output
Sample Input
1 1
Sample Output
5.3333
Source
Andrew Stankevich Contest 3
Manager
mathlover
题目大意:
给了两个圆柱的半径 r1,r2,他们的轴线垂直相交,让你求的是相交部分的体积。
解题思路:
这个题目首先我们对其积分:得到一个公式:
∫r0r12−x2−−−−−−−√∗r22−x2−−−−−−−√dy\int_0^r\sqrt{r1^2-x^2}*\sqrt{r2^2-x^2}dy
我们现在用正常的积分公式积不出来,我们就可以采用辛普森积分法进行积分,可以当作模板用
My Code:
Two Cylinders
Special Judge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Submit Statistic Next Problem
Problem Description
In this problem your task is very simple. Consider two infinite cylinders in three-dimensional space, of radii R1 and R2 respectively, located in such a way that their axes intersect and are perpendicular. Your task is to find the volume of their intersection.
Input
Input file contains two real numbers R1 and R2 (1 <= R1,R2 <= 100).
Output
Output the volume of the intersection of the cylinders. Your answer must be accurate up to 10-4.
Sample Input
1 1
Sample Output
5.3333
Source
Andrew Stankevich Contest 3
Manager
mathlover
题目大意:
给了两个圆柱的半径 r1,r2,他们的轴线垂直相交,让你求的是相交部分的体积。
解题思路:
这个题目首先我们对其积分:得到一个公式:
∫r0r12−x2−−−−−−−√∗r22−x2−−−−−−−√dy\int_0^r\sqrt{r1^2-x^2}*\sqrt{r2^2-x^2}dy
我们现在用正常的积分公式积不出来,我们就可以采用辛普森积分法进行积分,可以当作模板用
My Code:
/** 求两个交叉圆柱的体积 **/ #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> const double eps = 1e-9;///精度 using namespace std; double r1,r2; double f(double x)///积分函数 { return 8.0*(sqrt(r1*r1-x*x))*(sqrt(r2*r2-x*x)); } double simpson(double x,double y) { return (y-x)*(f(x)+f(y)+4*f((x+y)/2))/6.0; } double jifen(double x,double y)///积分区间[x,y] { double ans = simpson(x,y);///二分区间积分减小误差 double mid = (x+y)/2.0; double left = simpson(x,mid); double right = simpson(mid,y); if(fabs(ans-(left+right)) < eps) return ans; return jifen(x,mid)+jifen(mid,y); } int main() { while(~scanf("%lf%lf",&r1,&r2)) { if(r1<r2) swap(r1,r2); printf("%.6lf\n",jifen(0.0,r2)); } return 0; }
相关文章推荐
- 从全排列看递归
- 天才小毒妃 > 第905章 宁静,你输了
- 下拉刷新控件---SwipeRefreshLayout
- shell command:echo
- Developing your first FNC custom control
- AJAX 搜索自动显示练习
- Sums of Sums
- json解析
- 事务的四大属性ACID即事务的原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability.。
- Struts2常量介绍及说明
- 百度地图定位
- 滚动广告的实现
- POJ 3352 Road Constructio
- ACdream 1227Beloved Sons【二分图最佳匹配】
- Python菜鸟之路:Python基础-类(2)——成员、成员修饰符、异常及其他
- java之爬虫:爬取网页源代码
- JSON-lib框架,转换JSON、XML不再困难
- CGRect方法小汇总
- 友情从等待开翻船从冷漠结束
- UVa 1612 Guess (贪心+题意)