首页 > ACM题库 > HDU-杭电 > HDU 4808-Drunk[解题报告]HOJ
2015
09-18

HDU 4808-Drunk[解题报告]HOJ

Drunk

问题描述 :

Jenny is seriously drunk. He feels as if he is in an N-dimension Euclidean space, wandering aimlessly. In each step, he walks toward some direction and the “length” of each step will not exceed R. Technically speaking, Jenny is initially located at the origin of the N-dimension Euclidean space. Each step can be represented by a random N-dimension vector(x1, x2, … , xn) chosen uniformly from possible positions satisfying xi >= 0 and x12 + x22 + … <= R2.
Assume the expectation of his coordinate after his first step is (y1, y2, … , yn). He wants to know the minimum yi .

输入:

There are several (about 100,000) test cases, please process till EOF.
Each test case, only one line contains two integers N and R, representing the dimension of the space and the length limit of each step.(1 <= n <= 2 * 105, R <= 105).

输出:

There are several (about 100,000) test cases, please process till EOF.
Each test case, only one line contains two integers N and R, representing the dimension of the space and the length limit of each step.(1 <= n <= 2 * 105, R <= 105).

样例输入:

2 1

样例输出:

0.4244131816

题意:给定一个n维欧几里德空间中的一个n维向量(x1,x2,..,xn),xi>=0,sigma(xi^2)<=R^2.问xi最小值的期望.
解法:注意到空间球体的强对称性,即求x方向上的期望.这可以通过积分得出.在积分的过程中注意可以假设n维球体的体积为Vn=Pn*R^n.
#include <cstdio>
#include <cmath>
const int MAXN = 200000 + 5;

double t[MAXN];

int main()
{
    t[0] = acos(-1) / 2., t[1] = 1.;
    for (int i = 2; i < MAXN; ++ i) {
        t[i] = t[i - 2] * (i - 1) / i;
    }
    int n, R;
    while (scanf("%d%d", &n, &R) == 2) {
        double res = .5 * t[n + 1] * R / t[2];
        printf("%.10lf\n", res);
    }
    return 0;
}

参考:http://blog.csdn.net/u011277193/article/details/40735371