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 

pid=5052" target="_blank">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(计算几何)的更多相关文章

  1. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  2. BestCoder Round #14

    Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  4. 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town

    题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...

  5. 简单几何(水)BestCoder Round #50 (div.2) 1002 Run

    题目传送门 /* 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 */ /***** ...

  6. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves s ...

  7. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  8. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  9. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

随机推荐

  1. Eclipse wtp project dependent project facets问题

    wtp project会编译成一个war包,但在eclipse里debug时,依赖的project没有自动编译成jar包并打包到war的lib目录里. 原因:依赖project的facets未设置或未 ...

  2. Linux命令-目录处理命令:pwd

    pwd 显示当前目录的绝对路径

  3. 使用rman备份异机恢复数据库

    一.RMAN备份源库注意点: 最好保留rman备份日志 $rman target / log=backup.log RMAN>run { allocate channel t1 type dis ...

  4. sql中一列拆成两列

    declare @table table (name nvarchar(4))insert into @tableselect '张三' union allselect '李四' union alls ...

  5. informix-時間格式的各種用法

    以下是我在網路上所收集到的關於informix 時間的sql函數用法,有在使用informix資料庫的人,可以參考看看囉! today,返回現在系統日期 current 返回現在日期含時間,相當於sq ...

  6. [Jobdu] 题目1139:最大子矩阵

    题目描述: 已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵.比如,如下4 * 4的矩阵 0 -2 -7 09 2 -6 2-4 1 -4 ...

  7. 每日英语:Do Bicycle Helmet Laws Really Make Riders Safer?

    Typically in transportation — and most social arenas, for that matter — laws promoting safety precau ...

  8. 示例 Demo 工程和 API 参考链接

    Camera Explorer:有关 Windows Phone8 中有关增强 Camera API 的使用.文章链接 Filter Effects:对拍摄的照片或者图片库中的照片应用 Nokia I ...

  9. 三、请求库之requests模块

    一 介绍   #介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) #注意:requests库发送请求将网 ...

  10. CSS3多背景应用

    /*多背景应用*/ .wrapper { width: 640px; height: 1000px; margin: auto; background: url(./images/head.jpg) ...