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. eclipse tomcat 网页404的一个小问题

    之前一篇文章说过关于修改tomcat布置的应用的localhost路径.因为有两个项目在eclipse,所以我每次启动tomcat的时候都会加载两个项目, 但我其实只用调试其中一个项目,所以我就在se ...

  2. DataTables 配置和使用

    WEB后台开发,如果用的是Bootstrap框架,那这个表格神器你一定不要错过. 官方地址:https://datatables.net/ What?英文不好,没关系咱有中文的 http://data ...

  3. ASP.NET快速学习方案(.NET菜鸟的成长之路)

    想要快速学习ASP.NET网站开发的朋友可以按照下面这个学习安排进度走.可以让你快速入门asp.net网站开发!但也局限于一般的文章类网站!如果想学习更多的技术可以跟着我的博客更新走!我也是一名.NE ...

  4. 网页CSS

    CSS 样式表,(分三类:内联.内嵌.外部) 1,内联, 直接作于于 元素 例:   <p style="font-size:14px;"> 2,内嵌 作用于网页 首先 ...

  5. Webstorm10.0.3破解程序及汉化包下载、Webstorm配置入门指南

    核心提示: WebStorm 是jetbrains公司旗下一款JavaScript 开发工具.被广大中国JS开发者誉为“Web前端开发神器”.“最强大的HTML5编辑器”.“最智能的JavaSscri ...

  6. 前端笔试题目总结——应用JavaScript函数递归打印数组到HTML页面上

    数组如下: var item=[{ name:'Tom', age:70, child:[{ name:'Jerry', age:50, child:[{ name:'William', age:20 ...

  7. spring项目中监听器作用-ContextLoaderListener(项目启动时,加载一些东西到缓存中)

    作用:在启动Web容器时,自动装配Spring applicationContext.xml的配置信息. 因为它实现了ServletContextListener这个接口,在web.xml配置这个监听 ...

  8. oracle服务开机自启动

    1.修改oracle系统配置文件::/etc/oratab vi /etc/oratab orcl:/opt/oracle/product/10.2.0/db_1:Y 2.在 /etc/init.d/ ...

  9. C++ Primer 5th 第6章 函数

    正如第一章所说:C++的函数是一个能够完成一个功能的模块或者说是一段命名了的代码块. 如下图所示,函数可以重载,是一段实现某些功能命名了的代码. 一个完整的函数的构成有四部分: 1.返回类型 2.函数 ...

  10. 3月26日html(七)window document

    ---恢复内容开始--- 1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     v ...