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

  1. 4
  2. 1
  3. 2
  4. 5
  5. 9

Sample Output

  1. 1.0
  2. 3.0
  3. 274.0
  4. 1026576.0
  5.  
  6. 题意:一开始你没有一张卡片,每隔(n-1)!天你可以抽一张卡片,抽中每张卡片的概率为1/n,现在你要抽取n张卡片,期望是多少?
    分析:假设有n张卡片,你已经抽到了k张不同的卡片,则抽中(k+1)张不同的概率为:(n-k)/n,所以抽中(k+1)张的期望次数为n/(n-k),也就是平均抽n/(n-k)张才能抽到一张不同的卡片,期望即是平均值
  1.    即 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代码:
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. BigInteger [] a = new BigInteger [3010];
  7. a[1] = BigInteger.valueOf(1);
  8. for( int i = 2; i <= 3000; i ++ ) {
  9. a[i] = a[i-1].multiply(BigInteger.valueOf(i));
  10. }
  11. Scanner cin = new Scanner(System.in);
  12. int T;
  13. T = cin.nextInt();
  14. while( T > 0 ) {
  15. T --;
  16. int n;
  17. n = cin.nextInt();
  18. BigInteger sum = BigInteger.valueOf(0);
  19. for( int i = 1; i <= n; i ++ ) {
  20. sum = sum.add(a[n].divide(BigInteger.valueOf(i)));
  21. }
  22. System.out.print(sum);
  23. System.out.println(".0");
  24. }
  25. }
  26. }

  

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. Shiro权限框架与SpringMVC集成

    1.Shiro整合SpringMVC 我们学习Shiro框架肯定是要应用到Web项目上的,所以我们需要整合Shiro和SpringMVC 整合步骤: 第一步:SpringMVC框架的配置 spring ...

  2. 标签助手(TagHelper)

    1.什么是标签助手 Tag Helper 标签助手是服务端代码能够参与在 Razor 文件中创建和呈现HTML元素.例如,内置的 ImageTagHelper 可以将版本号追加到图像名称.无论何时更改 ...

  3. 深入理解java内存模型--读书笔记

    深入理解java内存模型 java内存模型的抽象 java线程之间的通信由java内存模型(JMM)控制,JMM决定一个线程对共享变量的写入何时对另一个线程可见 从抽象的角度来看,JMM决定了线程和主 ...

  4. c#小灶——注释和代码规范

    为什么要写注释? 早上我写完了代码,我和我的朋友们都能看懂,到了晚上,我还能看懂,一周后,就只有上帝能看懂了…… 将来我们写的代码量是很大的,代码又不像我们自然语言这么好理解,可能过段时间我们就不认识 ...

  5. BootStrap实现简单响应式导航菜单

    用BootStrap实现响应式导航栏,我会对其中的一些样式进行说明.   先上代码,是一个很简单的Demo. <!doctype html> <html> <head&g ...

  6. Linux服务部署Yapi项目(安装Node Mongdb Git Nginx等)

    Linux服务部署Yapi 一,介绍与需求 1,我的安装环境:CentOS7+Node10.13.0+MongoDB4.0.10. 2,首先安装wget,用于下载node等其他工具 yum insta ...

  7. asp.net core 一个中小型项目实战的起手式——项目搭建与仓储模式下的持久层创建(1)

    常规的中小型项目搭建方式一般是三层架构加上mvc与webapi作为一个主要框架,再加上一些第三方库,例如orm框架(EF.SqlSugar.Dapper等),API文档工具(Swagger)这些的应用 ...

  8. android——Fragment

    谷歌官方文档的介绍: https://developer.android.com/guide/components/fragments.html#Design Fragment 表示 Activity ...

  9. Spring 集成Kafka(完整版)

    前面的文章我们已经完成了Kafka基于Zookeeper的集群的搭建了.Kafka集群搭建请点我.记过几天的研究已经实现Spring的集成了.本文重点 jar包准备 集成是基于spring-integ ...

  10. 链表:如何实现LRU缓存淘汰算法?

    缓存淘汰策略: FIFO:先入先出策略 LFU:最少使用策略 LRU:最近最少使用策略   链表的数据结构: 可以看到,数组需要连续的内存空间,当内存空间充足但不连续时,也会申请失败触发GC,链表则可 ...