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

BestCoder Round #12

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;
}
时间: 2024-08-03 08:41:42

BestCoder Round #12 War(计算几何)的相关文章

计算几何(水)BestCoder Round #50 (div.2) 1002 Run

题目传送门 1 /* 2 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 3 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-8 19:54:14 8 * File Name :B.cpp 9 ************

BestCoder Round #91

传送门:http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+Round+%2391&source=1&searchmode=source A题:给你n种字母,每种字母有个权值vali,共cnti个,现在让你在里面挑出任意数量的字符,组合成一个字符串,该字符串的权值的计算方式为val1*1+val2*2+--+valn*n,让你输出字符串最大的权值是多少.这题很容易会有一个错误的贪心,就是把val为负的舍去,然后v

hdu 5163 Taking Bus (BestCoder Round #27)

Taking Bus                                                               Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 501    Accepted Submission(s): 203 Problem Description Bestland has a v

BestCoder Round #11 (Div. 2) 题解

HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 302    Accepted Submission(s): 229 Problem Description Bob and Alice got separated in the Square, they agreed that if they

BestCoder Round #4 前两题 hdu 4931 4932

第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[6]; 7 int main(){ 8 int cas; 9 scanf( "%d", &cas ); 10 while( cas-- ){ 11 for( int i = 0; i <

BestCoder Round #88

传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <ctime> 5 #include <cmath> 6 #include <iostream> 7 #include <algorithm> 8

HDU 5666 Segment——BestCoder Round #80

Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Silen August does not like to talk with others.She like to find some interesting probl

BestCoder Round #75 - King&#39;s Phone

Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut

BestCoder Round#15 1001-Love

http://acm.hdu.edu.cn/showproblem.php?pid=5082 Love Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 64    Accepted Submission(s): 51 Problem Description There is a Love country with many couples