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. 解决Android 5.1系统以上通知状态栏小图标仅仅显示白色问题

    看上图,想必大家都有遇到过吧.近期俺也遇到了,找到了解决方法,如今分享下也做个记录哈. 问题发生的规则是Android5.1或者以上的手机系统使用了非常多的颜色的通知图标,就会出现,怎么解决呢,非常e ...

  2. 谁占用了我的Buffer Pool?--【转】

    转自:http://blogs.msdn.com/b/apgcdsd/archive/2011/01/11/buffer-pool.aspx 我在做SQL Server 7.0技术支持的时候有客户问我 ...

  3. Spark in meituan http://tech.meituan.com/spark-in-meituan.html

    Spark在美团的实践 忽略元数据末尾 回到原数据开始处 引言:Spark美团系列终于凑成三部曲了,Spark很强大应用很广泛, 文中Spark交互式开发平台和作业ETL模板的设计都很有启发借鉴意义. ...

  4. Django的ORM中如何判断查询结果是否为空,判断django中的orm为空

    result= Booking.objects.filter() #方法一 .exists() if result.exists(): print "QuerySet has Data&qu ...

  5. Spring IOC和AOP 基础

    1 spring中注入资源是通过描述来实现的,在 spring 中是通过注解或者 XML 描述.spring 中IOC 注入方式有三种 1)构造方法注入 2)setter 注入 3)接口注入 1.1) ...

  6. hdu 2066 一个人的旅行(dijkstra)

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  7. dbrd 8.4.6 源代码编译安装

    ---------------------------- 0.系统环境 ---------------------------- db01 192.168.50.10 /dev/sdb1 主节点 db ...

  8. css语法和JS语法的对比

      CSS语法(不区分大小写) JavaScript语法(区分大小写) border border border-bottom borderBottom border-bottom-color bor ...

  9. 漫谈Linux下的音频问题(转)

    转自 http://www.kunli.info/2009/03/24/linux-sound-issue/ 现今的互联网,比较Linux和Windows的战争贴基本都成月经贴了.一群群激进的用户不断 ...

  10. 0066 阿里云大学的几道Java基础测试题

    阿里云大学的几道Java基础测试题: https://edu.aliyun.com/clouder/exam/intro/15 https://edu.aliyun.com/clouder/exam/ ...