码迷,mamicode.com
首页 > 其他好文 > 详细

BestCoder Round #12 War(计算几何)

时间:2014-10-06 04:14:39      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:acm   c   算法   

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\n",vc,vu);
        printf("%.6lf\n",vc/vu);
    }
    return 0;
}


BestCoder Round #12 War(计算几何)

标签:acm   c   算法   

原文地址:http://blog.csdn.net/bossup/article/details/39812625

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!