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. Windows 8 应用开发 - 应用栏

    原文:Windows 8 应用开发 - 应用栏      通过应用栏(AppBar)可以在需要时向用户显示各种应用命令.应用栏提供与用户当前页面或当前选定的内容相关的各种命令.默认情况下,应用栏处于隐 ...

  2. c++堆栈实现

    A Stack is a data-structure that You can only add an element to the top of the Stack, andYou can onl ...

  3. 详细说明XML分解(两)—DOM4J

    第一部分关于博客XML三接口,同时也为学习DOM4J该分析工具做准备.一般解析器基本上都实现了DOM和SAX这两组接口,DOM4J自然也不例外..DOM4J仅仅是经常使用解析器的当中一种,只是既然是实 ...

  4. 在汉澳sinox2014建立ZFS高可靠文件存储系统

    在汉澳sinox2014建立ZFS高可靠文件存储系统 汉澳sinox2014能够用比較小的固态硬盘安装,文件系统能够用zfs系统存放. 请准备一些硬盘,比方三块SCSI硬盘:da0,da1,da2 如 ...

  5. Linux 常用命令解析和Bash Shell使用示例脚本演示

     摘要 Linux命令是基于文本格式输入输出的一种程序,依照Unix哲学中强调的程序功能简单,输入宽松,输出严谨,各种程序组合能够具有更强大的功能,而具有这样的灵活性的主要原因是Linux规定程序 ...

  6. 【Linux探索之旅】第二部分第一课:终端Terminal,好戏上场

    内容简介 1.第二部分第一课:终端Terminal,好戏上场 2.第二部分第二课预告:命令行,世界尽在掌握 终端Terminal,好戏上场 随着第一部分的结束,我们进入了第二部分(小编你这好像是废话. ...

  7. C++ Primer 学习笔记_45_STL实践与分析(19)--建筑常规算法

    STL实践与分析 --泛型算法的结构 引言: 正如全部的容器都建立在一致的设计模式上一样,算法也具有共同的设计基础. 算法最主要的性质是须要使用的迭代器种类.全部算法都指定了它的每一个迭代器形參可使用 ...

  8. hdu 4876 ZCC loves cards(暴力)

    题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...

  9. oracle在imp订单具体解释

    oracle在imp订单具体解释 Oracle导入实用程序(Import utility)同意从数据库中提取数据,和写入数据到一个操作系统文件项目.imp所用的基本格式:imp[username[/p ...

  10. Chapter 1 Securing Your Server and Network(8):停止未使用的服务

    原文:Chapter 1 Securing Your Server and Network(8):停止未使用的服务 原文出处:http://blog.csdn.net/dba_huangzj/arti ...