#include<bits/stdc++.h>
using namespace std;
const int maxn = 2*1e5+7;
#define LL long long
#define pi acos(-1.0)
double si[maxn];
void init()
{
si[0]=1;
si[1]=1;
for(int i = 2;i<maxn;i++)
si[i]=si[i-2]*(i-1)/i;
}
int main()
{
init();
int r,n;
while(scanf("%d%d",&n,&r)!=EOF)
{
if(n&1)
printf("%.10lf\n",1.0*r/(n+1)/si[n]);
else
printf("%.10lf\n",1.0*r/(n+1)/(si[n]*pi/2));
}
}
Description
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(x
1, x
2, ... , x
n) chosen uniformly from possible positions satisfying x
i >= 0 and x
12 + x
22 + ... <= R
2.
Assume the expectation of his coordinate after his first step is (y
1, y
2, ... , y
n). He wants to know the minimum y
i .
Input
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 * 10
5, R <= 10
5).
Output
For each test case, print a real number representing the answer to the question above.
Your answer is considered correct if the difference between your answer and the correct one is less than 10
-6.
思路:这个题居然高数老师说过...它的公式其实就是x*f(x)的积分/f(x)的积分,f(x)=(r^2-x^2)^(n-1)/2,然后推推就出来了#includeusing namespace std;const int maxn = 2*1e5+7;#define LL long long#define pi acos(-1.0)double si[maxn];voi