2017福建省赛 FZU 2278 YYS 数学 大数

博客围绕手机RPG游戏Yinyangshi中卡片收集问题展开。玩家Kim收集卡片,有n种卡片,每次抽卡需W=(n - 1)!个硬币,每天得1个硬币。问题是求收集齐n种卡片的期望天数,还给出了输入输出格式及示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Yinyangshi is a famous RPG game on mobile phones.

Kim enjoys collecting cards in this game. Suppose there are n kinds of cards. If you want to get a new card, you need to pay W coins to draw a card. Each time you can only draw one card, all the cards appear randomly with same probability 1/n. Kim can get 1 coin each day. Suppose Kim has 0 coin and no cards on day 0. Every W days, Kim can draw a card with W coins. In this problem ,we define W=(n-1)!.

Now Kim wants to know the expected days he can collect all the n kinds of cards.

Input

The first line an integer T(1 ≤ T ≤ 10). There are T test cases.

The next T lines, each line an integer n. (1≤n≤3000)

Output

For each n, output the expected days to collect all the n kinds of cards, rounded to one decimal place.

Sample Input

4
1
2
5
9

Sample Output

1.0
3.0
274.0
1026576.0

题意:一开始你没有一张卡片,每隔(n-1)!天你可以抽一张卡片,抽中每张卡片的概率为1/n,现在你要抽取n张卡片,期望是多少?
分析:假设有n张卡片,你已经抽到了k张不同的卡片,则抽中(k+1)张不同的概率为:(n-k)/n,所以抽中(k+1)张的期望次数为n/(n-k),也就是平均抽n/(n-k)张才能抽到一张不同的卡片,期望即是平均值
   即 E(k+1) = n/(n-k)
   所以期望 E = (E(1)+E(2)+...+E(n))*(n-1)! = (n/n+n/(n-1)+...+n/1)*(n-1)! = n!/n + n!/(n-1) + ... + n!/1
参考博客:https://blog.youkuaiyun.com/hnust_xx/article/details/75807071
AC代码:
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		BigInteger [] a = new BigInteger [3010];
		a[1] = BigInteger.valueOf(1);
		for( int i = 2; i <= 3000; i ++ ) {
			a[i] = a[i-1].multiply(BigInteger.valueOf(i));
		}
		Scanner cin = new Scanner(System.in);
		int T;
		T = cin.nextInt();
		while( T > 0 ) {
			T --;
			int n;
			n = cin.nextInt();
			BigInteger sum = BigInteger.valueOf(0);
			for( int i = 1; i <= n; i ++ ) {
				sum = sum.add(a[n].divide(BigInteger.valueOf(i)));
			}
			System.out.print(sum);
			System.out.println(".0");
		}
	}
}                 

  

转载于:https://www.cnblogs.com/l609929321/p/9544230.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值