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. C# Windows Phone 8 WP8 高级开发,制作不循环 Pivot ,图片(Gallery)导览不求人! 内附图文教学!!

    原文:C# Windows Phone 8 WP8 高级开发,制作不循环 Pivot ,图片(Gallery)导览不求人! 内附图文教学!! 一般我们在开发Winodws Phone APP 的时候往 ...

  2. 使用QT 4.8.6 + Cmake 3.0.0 编译 最新版本OpenCv3.0.0

    mingw32 (x32) gcc g++ qt opencv- -- cmake -rc1 windows x64 参考文章: http://blog.csdn.net/qiurisuixiang/ ...

  3. DV工作流

  4. 解决adb server is out of date. killing...问题

    在运行 adb 命令时出现了例如以下提示: adb server is out of date.  killing... 导致 adb 无法正常启动,更无法运行其它命令. 有问题怎么办?百度呗.查了查 ...

  5. .net Quartz 服务 作业调度

    .net项目中使用Quartz   (1)在web.config中进行相关配置 <configSections> <section name="quartz" t ...

  6. 乐在其中设计模式(C#) - 解释器模式(Interpreter Pattern)

    原文:乐在其中设计模式(C#) - 解释器模式(Interpreter Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 解释器模式(Interpreter Pattern) 作 ...

  7. Interpolator(插值器)的种类

    Interpolator(插值器)的种类 Interpolator被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果accelerated(加速),decelerated(减速),repeat ...

  8. Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)(转)

    互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ...

  9. 【LeetCode】- Valid Palindrome(右回文)

    [ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...

  10. EL与JSTL注意事项汇总

    EL使用表达式(5一个 问题) JSTL使用标签(5问题) 什么是EL.它可以用做? EL全名Expression Language在JSP使用页面 格公式${表达式} 样例${requestScop ...