HDU 4808 Drunk(数学)

思路:这个题居然高数老师说过...它的公式其实就是x*f(x)的积分/f(x)的积分,f(x)=(r^2-x^2)^(n-1)/2,然后推推就出来了


#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  1  2 + x  2  2 + ... <= 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.

Sample Input

2 1

Sample Output

0.4244131816


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值