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.csdn.net/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");
}
}
}

  

2017福建省赛 FZU 2278 YYS 数学 大数的更多相关文章

  1. 2017福建省赛 FZU2272~2283

    1.FZU2272 Frog 传送门:http://acm.fzu.edu.cn/problem.php?pid=2272 题意:鸡兔同笼通解 题解:解一个方程组直接输出就行 代码如下: #inclu ...

  2. 【Floyd最短路】第七届福建省赛 FZU Problem 2271 X

    http://acm.fzu.edu.cn/problem.php?pid=2271 [题意] 给定一个n个点和m条边的无向连通图,问最多可以删去多少条边,使得每两个点之间的距离(最短路长度)不变. ...

  3. 2017福建省赛 L Tic-Tac-Toe 模拟

    Kim likes to play Tic-Tac-Toe. Given a current state, and now Kim is going to take his next move. Pl ...

  4. YYS FZU - 2278 (期望)JAVA

    题目链接: G - YYS FZU - 2278 题目大意: 我们现在想要收集到n个卡片,现在已知抽到每种卡片的概率为1/n,现在每隔(n-1)!天就可以进行一次抽奖,问收集齐所有卡片的期望天数. 具 ...

  5. Wannafly交流赛1_B_硬币【数学】

    Wannafly交流赛1_B_硬币[数学] 链接:https://www.nowcoder.com/acm/contest/69/B 来源:牛客网 题目描述 蜥蜴的生日快到了,就在这个月底! 今年,蜥 ...

  6. 2017 湖南省赛 K Football Training Camp

    2017 湖南省赛 K Football Training Camp 题意: 在一次足球联合训练中一共有\(n\)支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为 ...

  7. G - YYS FZU - 2278 数学期望 (大数)

    Yinyangshi is a famous RPG game on mobile phones. Kim enjoys collecting cards in this game. Suppose ...

  8. Problem 2278 YYS (FZU + java大数)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2278 题目: 题意: 有n种卡牌,每种卡牌被抽到的概率为1/n,求收齐所有卡牌的天数的期望. 思路: 易推得公 ...

  9. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

随机推荐

  1. 【iOS】The filename 未命名.ipa in the package contains an invalid character(s)

    提交 APP 到苹果官网审核时遇到了这个问题,如图: 其实就是不支持中文,随便换个英文名就行了. 参考:http://blog.csdn.net/u011439689/article/details/ ...

  2. Filebeat6.3文档—Log input配置

    Filebeat6.3文档-Log input配置 paths 日志加载的路径.例如加载某一子目录级别下面路径的日志:/var/log/*/*.log.这表示会去加载以.log结尾的/var/log下 ...

  3. Linux学习之自动配置部署——初用expect

    主机A连接主机B 免密登陆 + 自动部署 expect实现自动的交互式任务 ——— send 向进程发送字符串(输入) ——— expect 从进程接受字符串 ——— spawn 启动新进程 ——— ...

  4. Activiti6系列(1)- 核心数据库表及字段注释说明

    前言 本文是根据<疯狂工作流讲义-Activiti6.0>一书中提取过来的,有兴趣的可以去当当网买这本书,讲的很不错,最后还有实战案例. 虽然是提取过来的,但完全靠手打梳理,觉得有用的小伙 ...

  5. 0x02 递推与递归

    [例题]CH0301 递归实现指数型枚举 #include <iostream> #include <cstdio> #include <algorithm> #i ...

  6. mybatis的一对多双向映射

    连表查询 select id resultType resultMap resultType和resultMap不能同时使用 association 属性 映射到多对一中的“一”方的“复杂类型”属性, ...

  7. 安装Windows Server 2008

    下面介绍一下,Windows Server操作系统安装,以及在企业中的应用,在小型企业中可以使用不同的版本搭建不同类型的服务,小型企业中可以搭建Web服务,FTP服务,以及DNS和DHCP服务等,在大 ...

  8. 实现API管理系统的几个重要关键词

    管理API的需求源自于Web API开展业务.从2006年开始,然后逐渐成熟,并在2016年之前进入市场.无论是通过代理现有API的管理网关.本身作为用于部署API本身的网关的一部分,还是作为连接层在 ...

  9. 数据库系统原理之SQL(三)

    数据库系统原理之SQL(三) 1. SQL的组成 1. 数据查询 2. 数据定义 3. 数据操作 4. 数据控制 2. 数据定义语言 CREATE创建数据库或数据库对象 创建数据库 ~~~ CREAT ...

  10. Gitment评论插件的使用

    前言 继上一篇的 GitPages部署自己的网站 现在开始添加博客的评论插件Gitment.这里的话我是使用hexo添加gitment插件,如果不是使用hexo,请到官网指定这里. 开始 第一步 注册 ...