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
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
[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
Recommend
这是个纯数学题,考的是积分,以及一种通过面求体的方法。
题解如下:
1003 War 首先要求出球体和圆柱体之间的相交的体积。 然后总体积减去相交的体积就是并的体积。 求交的体积可以如上图,想像成一个矩阵和一个圆相交部分绕X轴旋转而成的一个东西,就是上图阴影部分绕X轴出来的一个东西。 然后体积公式为 ∫ HR 0 2πy∗2R 2 −y 2 − − − − − − − √ dy=−43 π(R 2 −y 2 ) 3/2 | HR 0 总共有五种情况,还有四种情况是 这个直接计算中间的球体即可。 直接计算圆柱体。 这个可以直接套用公式,把HR改成R。(这个地方我的方法和它不一样) 分成黄公和灰色两部分计算,灰色部分是圆柱体好算。 黄色部分可以套用公式: ∫ HR r 0 2πy∗2R 2 −y 2 − − − − − − − √ dy=−43 π(R 2 −y 2 ) 3/2 | HR r 0 其中 r 0 =R 2 −HZ 2 − − − − − − − − − √
#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <functional> #include <sstream> #include <iomanip> #include <cmath> #include <cstdlib> #include <ctime> #pragma comment(linker, "/STACK:102400000,102400000") typedef long long ll; //typedef pair<int,int> 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<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define scan(n) scanf("%d",&n) #define scan2(n,m) scanf("%d%d",&n,&m) #define scans(s) scanf("%s",s); #define ini(a) memset(a,0,sizeof(a)) #define FILL(a,n) fill(a,a+maxn,n) #define out(n) printf("%d\n",n) ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b);} #define mk(n,m) make_pair(n,m) using namespace std; double R,HR,HZ; double Int1(double y) //HZ>=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; }