hdu 5060 求球与圆柱相交体积

War

Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 124    Accepted Submission(s): 34
Special Judge


Problem Description
Long long ago there are two countrys in the universe. Each country haves its own manor in 3-dimension space. Country A's manor occupys x^2+y^2+z^2<=R^2. Country B's manor occupys x^2+y^2<=HR^2 && |z|<=HZ. There may be a war between them. The occurrence of a war have a certain probability. 
We calculate the probability as follow steps.
1. VC=volume of insection manor of A and B.
2. VU=volume of union manor of A and B.
3. probability=VC/VU
 

Input
Multi test cases(about 1000000). Each case contain one line. The first line contains three integers R,HR,HZ. Process to end of file.

[Technical Specification]
0< R,HR,HZ<=100
 

Output
For each case,output the probability of the war which happens between A and B. The answer should accurate to six decimal places.
 

Sample Input
 
   
1 1 1 2 1 1
 

Sample Output
 
   
0.666667 0.187500
 

Source
BestCoder Round #12
 

Recommend
heyang   |   We have carefully selected several similar problems for you:   5061  5059  5058  5057  5053 

这是个纯数学题,考的是积分,以及一种通过面求体的方法。

题解如下:

1003 War

首先要求出球体和圆柱体之间的相交的体积。
然后总体积减去相交的体积就是并的体积。
求交的体积可以如上图,想像成一个矩阵和一个圆相交部分绕X轴旋转而成的一个东西,就是上图阴影部分绕X轴出来的一个东西。
然后体积公式为  HR 0  2πy2R 2 y 2  − − − − − − −   dy=43 π(R 2 y 2 ) 3/2 | HR 0  
总共有五种情况,还有四种情况是

这个直接计算中间的球体即可。

直接计算圆柱体。

这个可以直接套用公式,把HR改成R。(这个地方我的方法和它不一样)

分成黄公和灰色两部分计算,灰色部分是圆柱体好算。	
黄色部分可以套用公式:
 HR r 0   2πy2R 2 y 2  − − − − − − −   dy=43 π(R 2 y 2 ) 3/2 | HR r 0   
其中r 0 =R 2 HZ 2  − − − − − − − − −    

 
  
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
//typedef pair pii; 
#define INF 1e9
#define MAXN 100005
#define MAXM 100
const int maxn = 1005;
const int mod = 1000000009;
#define eps 1e-6
#define PI 3.1415926535897932384626433
#define rep(i,n) for(int i=0;i=R && R>=HR
{
	return -4.0/3 * PI * pow(R*R - y*y, 3.0/2);
}
int main()
{
#ifndef ONLINE_JUDGE  
	freopen("in.txt","r",stdin);  
	//   freopen("out.txt","w",stdout);  
#endif
	
	while(~scanf("%lf%lf%lf",&R,&HR,&HZ))
	{
		double VU = 4.0/3 * PI * R * R * R + PI * HR * HR * 2 * HZ;
		double VC = 0;
		if(HZ >= R && R >= HR) VC = Int1(HR) - Int1(0);
		else if(HZ >= R && HR >= R) VC = 4.0/3 * PI * R * R * R;
		else if(R >= sqrt(HR*HR + HZ*HZ)) VC = PI * HR * HR * 2 * HZ;
		else if(R >= HZ && HR >= R) VC = 2*PI*HZ*(R*R-HZ*HZ)+ Int1(R) - Int1(sqrt(R*R-HZ*HZ));
		else if(R >= HZ && R >= HR && R < sqrt(HR*HR + HZ*HZ)) VC = 2*PI*HZ*(R*R-HZ*HZ)+ Int1(HR) - Int1(sqrt(R*R-HZ*HZ));
		double ans = VC / (VU - VC);
		printf("%.6lf\n",ans);
	}
	return 0;
} 


 
  

你可能感兴趣的:(积分,数学)