Two Cylinders

Special JudgeTime Limit: 10000/5000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

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
 

算法:先积分,再套用Simpson模板即可。
至于积分,就是高数的内容了,把2个圆柱中半径比较小的设为r1,半径较大的设为r2.
我们把小圆柱的轴线重叠z轴放置,大圆柱的轴线重叠y轴放置。
假设有一个平行于yOz平面的平面截得两圆柱的相交部分,得到一个截面,这个截面的面积是多少呢?
假设截面与x轴交于点(x,0,0),又因为是2个圆柱的相交部分,所以截面的一边长为2√(r12-x2)
同理,另一边长为2√(r22-x2)
最后得到一个积分:

8∫√(r12-x2)(r22-x2)dx
对[0,r1]求积分,就是结果。
 
直接积出来是很困难的,下面就是直接套Simpson模板了,写出全局函数F,其他没什么了。
 
 

 #include<cstdio>
#include<cmath>
#include <algorithm>
using namespace std; double r1,r2; // simpson公式用到的函数,就是待积分函数
double F(double x)
{
return sqrt(r1*r1-x*x)*sqrt(r2*r2-x*x);
} // 三点simpson法。这里要求F是一个全局函数
double simpson(double a, double b)
{
double c = a + (b-a)/;
return (F(a)+*F(c)+F(b))*(b-a)/;
} // 自适应Simpson公式(递归过程)。已知整个区间[a,b]上的三点simpson值A
double asr(double a, double b, double eps, double A)
{
double c = a + (b-a)/;
double L = simpson(a, c), R = simpson(c, b);
if(fabs(L+R-A) <= *eps) return L+R+(L+R-A)/15.0;
return asr(a, c, eps/, L) + asr(c, b, eps/, R);
} // 自适应Simpson公式(主过程)
double asr(double a, double b, double eps)
{
return asr(a, b, eps, simpson(a, b));
} // 用自适应Simpson公式计算积分数值
double getValue()
{ return asr(, r1, 1e-)*; // 第一第二个参数为积分区间,第三个参数为精度
} int main()
{
while(~scanf("%lf%lf",&r1,&r2))
{
if(r1>r2)
swap(r1,r2);
printf("%.10f\n",getValue());
}
return ;
}

acdream:Andrew Stankevich Contest 3:Two Cylinders:数值积分的更多相关文章

  1. GYM 100608G 记忆化搜索+概率 2014-2015 Winter Petrozavodsk Camp, Andrew Stankevich Contest 47 (ASC 47)

    https://codeforces.com/gym/100608 题意: 两个人玩游戏,每个人有一个长为d的b进制数字,两个人轮流摇一个$[0,b-1]$的骰子,并将选出的数字填入自己的d个空位之中 ...

  2. Andrew Stankevich&#39;s Contest (1)

    Andrew Stankevich's Contest (1) 打一半出门了,回来才补完了...各种大数又不能上java..也是蛋疼无比 A:依据置换循环节非常easy得出要gcd(x, n) = 1 ...

  3. Andrew Stankevich's Contest (21) J dp+组合数

    坑爹的,,组合数模板,,, 6132 njczy2010 1412 Accepted 5572 MS 50620 KB C++ 1844 B 2014-10-02 21:41:15 J - 2-3 T ...

  4. 【模拟ACM排名】ZOJ-2593 Ranking (Andrew Stankevich’s Contest #5)

    真心是道水题,但找bug找的我想剁手了/(ㄒoㄒ)/~~ 注意几个坑点, 1.输入,getline(cin); / gets(); 一行输入,注意前面要加getchar();   输入运行记录的时候可 ...

  5. [Andrew Stankevich's Contest#21] Lempel-Ziv Compression

    Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)     Special Judge ...

  6. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  7. ACdream 1429 Rectangular Polygon

    Rectangular Polygon Time Limit: 1000MS   Memory Limit: 256000KB   64bit IO Format: %lld & %llu D ...

  8. ACdream 1427 Nice Sequence

    主题链接:http://115.28.76.232/problem? pid=1427 Nice Sequence Time Limit: 12000/6000MS (Java/Others)Memo ...

  9. acdream 1431 Sum vs Product

    Sum vs Product Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

随机推荐

  1. 远程连接mysql

    win系统下,连接别人的mysql或者让别人链接自己的mysql: 打开命令行cmd 进入mysql: mysql -u root -p mysql>use mysql;  mysql>s ...

  2. ORACLE STUDY NOTES 02

    [JSU]LJDragon's Oracle course notes In the first semester, junior year I.用户和权限 1.用户操作 --创建新用户 CREATE ...

  3. Jetty监控线程使用情况的配置

    Jetty监控线程使用情况配置 第一步,配置xml文件 jetty-monitor.xml 参数说明: threads: 线程池中的线程 busyThreads: 使用中的线程 idleThreads ...

  4. (转)命令行下,用 xcodebuild 生成ipa文件,通过 itms-services 协议安装

    准备工作:已经设置好,xcode中的证书,证书必须是企业级证书,才能通过 itms-services 协议安装 Step 1:  把以下代码保存到一个web目录中,命名为 “auto.plist”,注 ...

  5. HDU 4099 Revenge of Fibonacci (数学+字典数)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4099 这个题目就是一个坑或. 题意:给你不超过40的一串数字,问你这串数字是Fibonacci多少的开头 ...

  6. [AngularJS] Angular 1.5 $transclude with named slot

    In Angular 1.5, there is no link and compile. So use if you transclude, you cannot access the fifth ...

  7. ARM Cortex-M

    振荡周期.时钟周期.机器周期.指令周期 一个机器周期包含12个振荡周期或6个时钟周期 指令的执行时间称作指令周期(单.双.四周期) (1)振荡周期       振荡周期指为单片机提供定时信号的振荡源的 ...

  8. DataGrid( 数据表格) 组件[6]

    本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于Panel(面板).Resizeable(调整大小).LinkButton(按钮).Pageination( ...

  9. (四)《Java编程思想》——可变参数列表

    以object数组为参数的方法实现可变参数列表 package chapter5; /** * 以object数组为参数的方法实现可变参数列表 */ class A { } public class ...

  10. java开发的web下载大数据时的异常处理

    同事用java开发了一个系统,其中有一个功能是下载大约10万笔数据到Excel中.当上线后,很多用户反映下载数据量大的时候就不能成功,但有时可以,所以结论就是系统不稳定,这个问题拖了很久没有解决. 在 ...