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. Android各种屏幕分辨率(VGA、HVGA、QVGA、WQVGA、WVGA、FWVGA) 具体解释

    看资料的时候常常看到各种VGA,全都混了,无奈,找了些资料总结了下,分享给大家: 这些术语都是指屏幕的分辨率. VGA:Video Graphics Array,即:显示画图矩阵,相当于640×480 ...

  2. OpenVPN-ng,为移动续航的应用层隧道

    VPN,让人觉得它总是做好事的,是逃离监管的途径,其实VPN已经成了逃离监管的唯一代名词.你看,无论是什么技术,IPSec也好,WEB代理也罢,仅仅要是加密了原始信息的技术,都能够叫做VPN,于是乎就 ...

  3. silverlight 和winform的结合使用

    silverlight 和winform的结合使用比较简单,将silverlight承载在页面上,页面运行在winform上的webbrowser中即可. 这样的情况下,我没找到页面中silverli ...

  4. C++ map简单运用

    #include <iostream> #include <string> #include <map> using namespace std; typedef ...

  5. GCD code block

    在这里积累一些片段,由于备忘录. + (DRClass *)sharedDR{ //创建小黑.正常ap模式仅仅有一个小黑,so static DRClass *aDR = nil; static di ...

  6. A WPF File ListView and ComboBox

    源码下载: Download FileListView_Version_2.zip Download FileListView_Version_2_Binaries.zip Download File ...

  7. Gradle构建多模块项目(转)

    废话不多说,直接进入主题. 1. 创建项目 首先创建项目,名称为 test: mkdir test && cd test gradle init 这时候的项目结构如下: ➜ test ...

  8. 在Apk应用程序内,查找某个Activity。

    转载请注明出处:http://blog.csdn.net/droyon/article/details/39933677 Intent intent = new Intent(Intent.ACTIO ...

  9. S如何解决安卓DK无法下载Package问题

    安装一些用户Android SDK后.打开Android SDK Manager下载API当总是显示"Done loading packages"却迟迟不能前进.自己也出现了这样的 ...

  10. Connect2015 简要整理

    2015 简要整理 去年 Connect(); 2014 Visual Studio Contact(); 直播笔记 对于我个人来说,今年 Connect(); 的三个重要发布: ASP.NET 5 ...