light oj 1248 - Dice (III)(期望)

light oj 1248 - Dice (III)(期望),第1张

概述Given a dice withnsides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the

Given a dice with n sIDes,you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair,that means when you throw the dice,the probability of occurring any face is equal.

For example,for a fair two sIDed coin,the result is 3. Because when you first throw the coin,you will definitely see a new face. If you throw the coin again,the chance of getting the opposite sIDe is 0.5,and the chance of getting the same sIDe is 0.5. So,the result is

1 + (1 + 0.5 * (1 + 0.5 * ...))

= 2 + 0.5 + 0.52 + 0.53 + ...

= 2 + 1 = 3

input

input starts with an integer T (≤ 100),denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 105).

Output

For each case,print the case number and the expected number of times you have to throw the dice to see all its faces at least once. Errors less than 10 will be ignored.

Sample inputOutput for Sample input

5

1

2

3

6

100

Case 1: 1

Case 2: 3

Case 3: 5.5

Case 4: 14.7

Case 5: 518.7377517640

 

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e⑻//typedef __int64 ll;#define fre(i,a,b) for(i = a; i <b; i++)#define free(i,b,a) for(i = b; i >= a;i--)#define mem(t,v) memset ((t),v,sizeof(t))#define ssf(n) scanf("%s",n)#define sf(n) scanf("%d",&n)#define sff(a,b) scanf("%d %d",&a,&b)#define sfff(a,c) scanf("%d %d %d",&b,&c)#define pf printf#define BUG pf("Hi")using namespace std;#define INF 0x3f3f3f3f#define N 100005double dp[N];int n;int main(){ int i,j,t,ca=0; sf(t); while(t--) { sf(n); mem(dp,0); for(i=n⑴;i>=0;i--) dp[i]=((n-i)*dp[i+1]+n)*1.0/(n-i); pf("Case %d: %.7lf",++ca,dp[0]); } return 0;}@H_301_84@@H_301_84@

@H_301_84@

@H_301_84@

@H_301_84@

@H_301_84@

@H_301_84@

总结

以上是内存溢出为你收集整理的light oj 1248 - Dice (III)(期望)全部内容,希望文章能够帮你解决light oj 1248 - Dice (III)(期望)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1017028.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存