War

Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 98    Accepted Submission(s): 28

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
 

题解及代码:

这道题的意思非常easy:给定中心重合的一个球和一个圆柱,求出其重合体积占全部体积的比例。

这题写起来非常麻烦,由于要分成5类分别写(可耻de把官方的图扣下来 = =!

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva25pZ2h0X2tha2E=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

分类大致就是分成这5类。积分的方式这里使用的是simpson积分法。仅仅要知道被积函数和上下限就能够了,不用自己做不定积分。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const double pi=3.14159265358979,eps=1e-7;
double r,hr,hz; double f(double n)
{
return pi*(r*r-n*n);
} double simpson(double a,double b)
{
return (b-a)/6.0*(f(a)+4*f((a+b)/2.0)+f(b));
} double cal(double a,double b)
{
double sum=simpson(a,b),mid=(a+b)/2.0;
double t=simpson(a,mid)+simpson(mid,b); if(fabs(t-sum)<eps) return sum; return cal(a,mid)+cal(mid,b);
} int main()
{ while(scanf("%lf%lf%lf",&r,&hr,&hz)!=EOF)
{
double v=0,hv=0;
if(hr>=r&&hz>=r)
{
v=4.0/3.0*pi*r*r*r;
hv=2*pi*hr*hr*hz;
printf("%.6lf\n",v/hv);
continue;
}
if(hr>=r&&hz<r)
{
v=4.0/3.0*pi*r*r*r;
double t=2*cal(hz,r);
hv=2*pi*hr*hr*hz;
printf("%.6lf\n",(v-t)/(hv+t));
continue;
}
if(r*r>=hr*hr+hz*hz)
{
v=4.0/3.0*pi*r*r*r;
hv=2*pi*hr*hr*hz;
printf("%.6lf\n",hv/v);
continue;
}
if(hr<r&&hz>=r)
{
v=4.0/3.0*pi*r*r*r;
double t=2*cal(sqrt(r*r-hr*hr),r)+2*sqrt(r*r-hr*hr)*pi*hr*hr;
hv=2*pi*hr*hr*hz;
printf("%.6lf\n",t/(hv+v-t));
continue;
}
v=4.0/3.0*pi*r*r*r;
hv=2*pi*hr*hr*hz;
double t=2*cal(sqrt(r*r-hr*hr),hz)+2*sqrt(r*r-hr*hr)*pi*hr*hr;
printf("%.6lf\n",t/(hv+v-t));
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

hdu 5060 War的更多相关文章

  1. hdu 5060 五种情况求圆柱体与球体交

    http://acm.hdu.edu.cn/showproblem.php?pid=5060 官方题解http://bestcoder.hdu.edu.cn/给复杂了 实际上用圆柱体与球体体积差的积分 ...

  2. hdu 3345 War Chess

    War Chess Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  3. HDU - 3035 War(对偶图求最小割+最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3035 题意 给个图,求把s和t分开的最小割. 分析 实际顶点和边非常多,不能用最大流来求解.这道题要用 ...

  4. hdu 1140:War on Weather(计算几何,水题)

    War on Weather Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. HDU - 3345 War Chess 广搜+优先队列

    War chess is hh's favorite game: In this game, there is an N * M battle map, and every player has hi ...

  6. HDU 5060

    题意略. 这个题目最关键的是在于计算球冠的体积.令球冠体积为V. 我们可以用祖暅原理来计算V, 这里,可以看出,球冠的体积等于左图的上半个圆柱减去那个倒扣的圆台. 祖暅原理:界于两个平行平面之间的两个 ...

  7. hdu 4005 The war

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4005 In the war, the intelligence about the enemy is ...

  8. War Chess (hdu 3345)

    http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...

  9. HDU 2435 There is a war

    There is a war Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...

随机推荐

  1. 【buildroot-2011.11】You may have to install &#39;g++&#39; on your build machine

    buildroot - 2011.11 当进行交叉编译.例如像以下错误提及演示: "You may have to install 'g++' on your build machine&q ...

  2. CentOS6.5 Nginx优化编译配置[续]

    继续上文CentOS6.5 Nginx优化编译配置本文记录有关Nginx系统环境的一些细节设置,有关Nginx性能调整除了配置文件吻合服务器硬件之前就是关闭不必要的服务.磁盘操作.文件描述符.内核调整 ...

  3. 【shell文字】mysql每日备份shell文字

    每天固定时间使用mysqldump 备份mysql数据. #!/bin/bash #每天早上4点, mysql备份数据 orangleliu #chmod 700 backup.sh #crontab ...

  4. Morphia采用

    Morphia配合mongoDB喜欢Hibernate关系型数据库.也能够想到Morphia于MongoDB它调用上述的基础上,mongoDB语法. 于java直接通话Morphia的api它会变得更 ...

  5. 自己定义actionbar

    android中的actionbar可提供自己定义view.详细是先写好自己定义view的布局,然后在代码中获取Actionbar对象.调用 setCustomView方法. 可是这样,它还是会显示前 ...

  6. SQL 编码标准

    1. 你必须从别名表,易于使用的表,该表列 实例 select owner,object_id,name from a,b where a.id=b.id; 假设是不正确的别名表.我知道你是怎么访问表 ...

  7. Java Swing 树状组件JTree的使用方法(转)

    树中特定的节点可以由 TreePath(封装节点及其所有祖先的对象)标识,或由其显示行(其中显示区域中的每一行都显示一个节点)标识.展开 节点是一个非叶节点(由返回 false 的 TreeModel ...

  8. 大哥可以写KMP该——达到strstr()

    在最后采访,面试官要求实现strstr(),当场就蒙了. 这个题目是模式匹配问题.<算法导论>里列出了几种字符串匹配算法: 朴素算法 |  Rabin-Karp | 有限自己主动机算法 | ...

  9. freemarker错误九

    1.错误叙述性说明 五月 30, 2014 11:52:04 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template p ...

  10. Poj3414广泛搜索

    <span style="color:#330099;">/* D - D Time Limit:1000MS Memory Limit:65536KB 64bit I ...