acdream 1234 Two Cylinders

Two Cylinders

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

SubmitStatisticNext
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

题解及代码:

这道题的意思很简单,就是求两个垂直相交的圆柱的重合体积。推导的思想可以见:点击打开链接

根据上面的方法我们可以推出截面公式是sqrt(R*R-x*x)*sqrt(r*r-x*x),然后积分的上下限是0--r。

虽然这公式推出来了,但是积分很困难(没推出来= =!),下面的代码用的是辛普森积分法,学习了一下,挺简单的。

主要就是这个:

这个公式在数比较小的时候,误差不大,但是数比较大的时候,误差就很大了,所以计算过程中要使用二分来把区间减小,减小误差。

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-7;

double R,r;

double f(double n)
{
    return 8*sqrt(R*R-n*n)*sqrt(r*r-n*n);
}

double simpson(double a,double b)
{
    return (b-a)/6.0*(f(a)+4*f((a+b)/2.0)+f(b));
}

double cal(double a,double b)
{
    double sum=simpson(a,b),mid=(a+b)/2.0;
    double t=simpson(a,mid)+simpson(mid,b);

    if(fabs(t-sum)<eps) return sum;
    return cal(a,mid)+cal(mid,b);
}
int main()
{
    scanf("%lf%lf",&R,&r);
    if(R<r) swap(R,r);

    printf("%.5lf\n",cal(0,r));
    return 0;
}
时间: 2024-08-11 09:53:31

acdream 1234 Two Cylinders的相关文章

Acdream 1234 Two Cylinders 自适应辛普森

题目链接:点击打开链接 给定r1,r2 表示2个圆柱体的半径 这两个圆柱体高是正无穷,互相垂直,问相交的最大面积 #include <stdio.h> #include <string.h> #include <iostream> #include <cmath> #define M 410 #define inf 0x3f3f3f3f const double eps = 1e-8; template <class T> inline bool

[2016-04-21][light]OJ[1234][Harmonic Number]

时间:2016-04-21 22:18:26 星期四 题目编号:[2016-04-21][light]OJ[1234][Harmonic Number] 题目大意:求∑nk=11kn∈(1,108),精确到10?8求∑k=1n1kn∈(1,108),精确到10?8 分析: 想法是打表,然后输出,但是直接打表会爆内存 解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值 对应的整百就是n

ACdream 1203 - KIDx&#39;s Triangle(解题报告)

KIDx's Triangle Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description One day, KIDx solved a math problem for middle students in seconds! And than he created this problem. N

acdream 1738 世风日下的哗啦啦族I

原题链接:http://acdream.info/problem?pid=1738 树套树裸题,如下: 1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #define lc root<<1 7 #define rc root<<1|1 8 using std::so

数学 ACdream 1196 KIDx&#39;s Triangle

题目传送门 1 /* 2 这道题花了好长时间AC,思路有,但是表达式少写了括号一直乱码,囧! 3 注意:a==0时要特判:) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 #include <cmath> 11 using namespace std; 1

ACdream 之ACfun 题解

A - ACfun Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description 题目链接点击打开链接 As a former ACMer, "AC" is a special abbreviated word which can bring much pleasure to me. Sometimes it means

Ubuntu下快速搭建ACdream Online Judge v1.5.3

原文:https://github.com/KIDx/ACdream#%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96%E6%A8%A1%E5%9D%97 安装依赖 $ sudo apt-get update $ sudo apt-get install imagemagick $ sudo apt-get install python-software-properties python g++ make $ sudo apt-get install libcairo2

ACdream 1157 Segments(CDQ分治)

题目链接:http://acdream.info/problem?pid=1157 Problem Description 由3钟类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i (1-base) 删除第i条增加的线段,保证每条插入线段最多插入一次,且这次删除操作一定合法3) Q L R(1 <= L <= R <= 1000000000) 查询目前存在的线段中有多少条线段完全包含[L,R]这个线段,线段X

ACDream - Chasing Girl

先上题目: Chasing Girl Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description YYS 是SCAU_ACM里相当有名气的高富帅, 又因为他曾代表SCAU参加 World Final 而被各路亲朋好友仰慕.但YYS 又有另外一个嗜好,就是泡妞.在大学的时候,他经常去找各个女友玩耍, 但在路上却又整天遇到膜拜他的渣渣