zoukankan      html  css  js  c++  java
  • BestCoder Round #12 War(计算几何)

    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 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
     

    Recommend
    heyang   |   We have carefully selected several similar problems for you:  5061 5059 5058 5053 5052 
     题意:
    给你一个球心在原点.半径为r的球和一个圆柱体。圆柱体半径为hr,高为hz然后通径为z轴.然后通径中点也在原点。

    然后问你相交部分的体积vc/体积并vu。
    思路:
    这题因为原点中点都在原点所以比較好做。一前还没怎么写过计算几何的题。因为最后一题不会。仅仅有硬着头皮上了。

    我们就分类讨论。r,和hr的大小。

    然后在讨论下圆柱体有没有穿出球体。即sqrt(r*r-hr*hr)和r的大小。

    对于一部分的球体的体积用用定积分.积出来为PI*r*r*z-PI*z*z*z/3|上下限。

    具体见代码:
    #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
    ",vc,vu);
            printf("%.6lf
    ",vc/vu);
        }
        return 0;
    }
    


  • 相关阅读:
    bzoj1662: [Usaco2006 Nov]Round Numbers 圆环数
    畅通工程——D
    Constructing Roads——F
    FatMouse's Speed——J
    Tickets——H
    免费馅饼——G
    Max Sum Plus Plus——A
    Super Jumping! Jumping! Jumping!——E
    Fling——K
    #define is unsafe——I
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/6762147.html
Copyright © 2011-2022 走看看