fzu 2278 YYS 数学

来源:互联网 发布:数据加密 ipguard 编辑:程序博客网 时间:2024/05/22 05:21

Problem 2278 YYS

Time Limit: 1000 mSec    Memory Limit : 262144 KB

 Problem Description

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

41259

 Sample Output

1.03.0274.01026576.0

 Source

第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)

依次地做独立试验,其中每次实验有n种等概率的结果,问:要使得每种结果都至少出现一次平均需要做多少次试验。
答案:n\left(1+\frac{1}{2}+\cdots +\frac{1}{n}\right)

import java.io.BufferedInputStream;import java.io.PrintWriter;import java.math.BigDecimal;import java.math.BigInteger;import java.util.Scanner;public class Main {public static void main(String[] args) {new Task().solve();}}class Task {Scanner in = new Scanner(new BufferedInputStream(System.in)) ;PrintWriter out = new PrintWriter(System.out);final int N = 3000 ;BigInteger[] F = new BigInteger[N+1] ;void solve(){F[0] = BigInteger.ONE ;for(int i = 1 ; i <= N ; i++){F[i] = F[i-1].multiply(BigInteger.valueOf(i)) ;}int t = in.nextInt() ;while(t-- > 0){int n = in.nextInt() ;BigInteger sum = BigInteger.ZERO ;for(int i = 1 ; i <= n ; i++){sum = sum.add( F[n].divide(BigInteger.valueOf(i))) ;}out.print(sum);out.println(".0") ;}out.flush() ;}}





原创粉丝点击