hdu 5060 War

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

BestCoder Round #12

题解及代码:

这道题的意思很简单:给定中心重合的一个球和一个圆柱,求出其重合体积占所有体积的比例。

这题写起来很麻烦,因为要分成5类分别写(可耻de把官方的图扣下来 = =!)

分类大致就是分成这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;
}
时间: 2024-09-30 06:26:32

hdu 5060 War的相关文章

HDU 3035 War(对偶图求最小割)

HDU 3035 War 题目链接 题意:根据图那样,给定一个网络,要求阻断s到t,需要炸边的最小代价 思路:显然的最小割,但是也显然的直接建图强行网络流会超时,这题要利用平面图求最小割的方法,把每一块当成一个点,共有边连边,然后每一个路径就是一个割,然后最短路就是最小割了 代码: #include <cstdio> #include <cstring> #include <vector> #include <queue> using namespace s

hdu 3345 War Chess (bfs+优先队列)

War Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1732    Accepted Submission(s): 416 Problem Description War chess is hh's favorite game: In this game, there is an N * M battle map, an

hdu 3345 War Chess

War Chess Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 5   Accepted Submission(s) : 3 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description War chess is hh's favorite ga

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3035 题意 给个图,求把s和t分开的最小割. 分析 实际顶点和边非常多,不能用最大流来求解.这道题要用平面图求最小割的方法: 把面变成顶点,对每两个面相邻的边作一条新边.然后求最短路就是最小割了. 另外,外平面分成两个点,分别是源点和汇点,源点连左下的边,汇点连右上的边,这样跑出来才是正确的. 建图参考自:https://blog.csdn.net/accelerator_/article/deta

【图论】网络流总结

[图论]网络流总结 最大流部分 网络流题目的关键:看出是网络流而且确定正确的模型 最大流算法:用来解决从源点s到汇点t,整个网络最多能输送多少流量的题目 模板: #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; const int MAXNODE = 105 * 2; const int MAXEDGE = 10000

hdu 4005 The war

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4005 In the war, the intelligence about the enemy is very important. Now, our troop has mastered the situation of the enemy's war zones, and known that these war zones can communicate to each other direc

HDU 4005 The war(双连通好题)

HDU 4005 The war 题目链接 题意:给一个连通的无向图,每条边有一个炸掉的代价,现在要建一条边(你不不知道的),然后你要求一个你需要的最少代价,保证不管他建在哪,你都能炸掉使得图不连通 思路:炸肯定要炸桥,所以先双连通缩点,得到一棵树,树边是要炸的,那么找一个最小值的边,从该边的两点出发,走的路径中,把两条包含最小值的路径,的两点连边,形成一个环,这个环就保证了最低代价在里面,除了这个环以外的最小边,就是答案,这样的话,就利用一个dfs,搜到每个子树的时候进行一个维护即可 代码:

HDU 2435 There is a war (网络流-最小割)

There is a war Problem Description There is a sea. There are N islands in the sea. There are some directional bridges connecting these islands. There is a country called Country One located in Island 1. There is another country called Country Another

There is a war (hdu 2435 最小割+枚举)

There is a war Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 970    Accepted Submission(s): 277 Problem Description There is a sea. There are N islands in the sea. There are some directional