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. WCF-001:WCF的发布

    随着“云”时代的到来,“云”已经无处不在了.什么是“云”,无非就是利用互联网强大的功能建立多个服务器,然后再利用互联网的传输数据的特点将数据从某个服务器中读取出来或者将你的数据上传上去.当然这个服务器 ...

  2. 嵌入式Linux学习小结

    这两个月一直在学习Linux.作为一名刚開始学习的人,学习期间难免磕磕碰碰.走弯路,可是,抱着不怕失败.多尝试的信念,终于还是坚持下来了. 如今已经清楚Linux的框架,知道怎么去开发一个Linux程 ...

  3. Agile/CMMI/Scrum

    Agile/CMMI/Scrum 一.背景介绍 在朋友(aehyok)的建议下,初步去了解Visual Studio Online,简称VS Online(即原来的 Team Foundation S ...

  4. 返璞归真 asp.net mvc (4) - View/ViewEngine

    原文:返璞归真 asp.net mvc (4) - View/ViewEngine [索引页] [源码下载] 返璞归真 asp.net mvc (4) - View/ViewEngine 作者:web ...

  5. Spring HTTPInvoker原理猜想(HTTP+序列化)

    没有查看源码,仅作参考 实现步骤: 一,客户端 (1),远程调用信息封装为远程调用对象 (2),序列化写入到远程调用HTTP请求中 (3),向服务器发送 (4),服务器端返回的HTTP响应结果 (5) ...

  6. 对XSD schema文件中elementFormDefault属性的理解

    Schema中的elementFormDefault elementFormDefault取值:qualified 或者 unqualified 在http://www.velocityreviews ...

  7. 跟我extjs5(03--在项目过程中加载文件)

    跟我extjs5(03--在项目过程中加载文件) 上一节中用sencha工具自己主动创建了一个项目.而且能够在浏览器中查看. 如今我们来看看js类载入过程. 例如以下图所看到的: watermark/ ...

  8. hdu4858 项目管理 bestcoder round1 B

    唔..弱弱的暴力水果 0操作时,将v加到u上,能够直接把v加到u相连的点上,这样输出时直接输出要求点的值. 布这种话反正我是超时了.. #include<cstdio> #include& ...

  9. Peter&#39;s Hobby

    主题链接 题意: 题意比較麻烦.. .n天,给出每天的叶子的一种状态(Dry , Dryish , Damp and Soggy),最有可能出现的天气序列(Sunny, Cloudy and Rain ...

  10. 查看oracle数据库的连接数以及用户

    查看oracle数据库的连接数以及用户 11.查询oracle的连接数2select count(*) from v$session;32.查询oracle的并发连接数4select count(*) ...