BestCoder Round #12 War(計算幾何),

來源:互聯網
上載者:User

BestCoder Round #12 War(計算幾何),
WarTime 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]
0< R,HR,HZ<=100
 
OutputFor 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 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 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\n",vc,vu);        printf("%.6lf\n",vc/vu);    }    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.