Bestcoder round #12 war (Computational ry)

Source: Internet
Author: User
War Time Limit: 8000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 81 accepted submission (s): 23
Special Judge


Problem descriptionlong 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
Inputmulti 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]
<R, HR, Hz <= 100
 
Outputfor each case, output the probability of the war which happens between A and B. The answer shoshould accurate to six decimal places.
Sample Input
1 1 12 1 1
 
Sample output
0.6666670.187500
 
Sourcebestcoder round #12
Recommendheyang | we have carefully selected several similar problems for you: 5061 5059 5058 5053 question: give you a ball at the origin. A ball with a radius of R and a cylinder. The radius of the cylinder is HR, the height is Hz, and the diameter is Z axis. Then, the midpoint of the diameter is also at the origin. Then ask the volume VC/volume of the intersection and Vu. Idea: This question is easier because the point at which the origin is located. I have not written any questions about computational ry before, because the last question won't. Only the scalp is on. We will discuss the classification. R, and HR size. Then, we will discuss whether the cylinder has passed through the sphere. That is, the size of SQRT (R * r-HR * hr) and R. Use a fixed integral for the volume of a part of the sphere. The product is pi * r * z-Pi * z/3 | upper and lower limits. For details, see the code:
#include<algorithm>#include<iostream>#include<string.h>#include<stdio.h>#include<math.h>using namespace std;const int INF=0x3f3f3f3f;const int maxn=100010;const double PI=acos(-1.0);const double eps=1e-8;typedef long long ll;int main(){    double r,hr,hz,vc,vu,d,a,b,hh;    while(~scanf("%lf%lf%lf",&r,&hr,&hz))    {        if(hr<r)        {            d=sqrt(r*r-hr*hr);            if(hz<=d)                vc=2*PI*hr*hr*hz;            else            {                hh=min(hz,r);                a=PI*r*r*hh-PI*hh*hh*hh/3;                b=PI*r*r*d-PI*d*d*d/3;                vc=2*(PI*hr*hr*d+a-b);            }        }        else        {            if(hz<=r)                vc=2*(PI*r*r*hz-PI*hz*hz*hz/3);            else                vc=4*PI*r*r*r/3;        }        vu=4*PI*r*r*r/3+PI*hr*hr*hz*2-vc;        //printf("%lf %lf\n",vc,vu);        printf("%.6lf\n",vc/vu);    }    return 0;}


Bestcoder round #12 war (Computational ry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.