2017福建省赛 FZU 2278 YYS 数学 大数
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 数学 大数的更多相关文章
- 2017福建省赛 FZU2272~2283
1.FZU2272 Frog 传送门:http://acm.fzu.edu.cn/problem.php?pid=2272 题意:鸡兔同笼通解 题解:解一个方程组直接输出就行 代码如下: #inclu ...
- 【Floyd最短路】第七届福建省赛 FZU Problem 2271 X
http://acm.fzu.edu.cn/problem.php?pid=2271 [题意] 给定一个n个点和m条边的无向连通图,问最多可以删去多少条边,使得每两个点之间的距离(最短路长度)不变. ...
- 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 ...
- YYS FZU - 2278 (期望)JAVA
题目链接: G - YYS FZU - 2278 题目大意: 我们现在想要收集到n个卡片,现在已知抽到每种卡片的概率为1/n,现在每隔(n-1)!天就可以进行一次抽奖,问收集齐所有卡片的期望天数. 具 ...
- Wannafly交流赛1_B_硬币【数学】
Wannafly交流赛1_B_硬币[数学] 链接:https://www.nowcoder.com/acm/contest/69/B 来源:牛客网 题目描述 蜥蜴的生日快到了,就在这个月底! 今年,蜥 ...
- 2017 湖南省赛 K Football Training Camp
2017 湖南省赛 K Football Training Camp 题意: 在一次足球联合训练中一共有\(n\)支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为 ...
- G - YYS FZU - 2278 数学期望 (大数)
Yinyangshi is a famous RPG game on mobile phones. Kim enjoys collecting cards in this game. Suppose ...
- Problem 2278 YYS (FZU + java大数)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2278 题目: 题意: 有n种卡牌,每种卡牌被抽到的概率为1/n,求收齐所有卡牌的天数的期望. 思路: 易推得公 ...
- hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...
随机推荐
- Lexical or preprocessor 'XXX/XXX.h' issue file not found
最近做第三方登录,引入了第三库,结果就出来个这个问题.如下图所示: 刚开始编译运行都没问题,可下次再打开时就报这个错误…… 一个比较弱智的解决办法: 1. 删除第三方库文件(删除到垃圾箱,而且还要在文 ...
- PID算法 旋转倒立摆与平衡车的区别。此贴后边会更新。
我做PID算法的背景和经历:本人之前电子信息科学与技术专业,对控制方向颇感兴趣,刚上大学时听到实验室老师说PID算法,那年在暑假集训准备全国电子设计竞赛,我正在练习做一个以前专科的题目,帆板角度控制系 ...
- 4. 源码分析---SOFARPC服务端暴露
服务端的示例 我们首先贴上我们的服务端的示例: public static void main(String[] args) { ServerConfig serverConfig = new Ser ...
- window下打jar包
比如我的项目在 F/Myjar F:\Myjar>ll'll' 不是内部或外部命令,也不是可运行的程序或批处理文件. F:\Myjar>cd mian系统找不到指定的路径. F:\Myja ...
- Xamarin 基础知识
Xamarin 跨平台处理: C#: if (Device.OS == TargetPlatform.Android) { Code…… } else if (Device.OS == TargetP ...
- codeforces679A_Bear and Prime 100 交互题
传送门 第一道交互题 题意: 电脑事先想好了一个数[,] 你会每次问电脑一个数是否是它想的那个数的因数 电脑会告诉你yes或no 至多询问20次 最后要输出它想的数是质数还是合数 思路: 枚举< ...
- Go中的结构体
前面我们或多或少的都使用了结构体这种数据结构,本身结构体也有很多特性,我们一一来看. 结构体的作用是将一个或者多个任一类型的变量组合在一起的数据类型,类似于我们在Java中class的作用.在结构体重 ...
- Vue系列:Websocket 使用配置
WebSocket 是什么? WebSocket 是一种网络通信协议.而且是在 HTML5 才开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. 为什么需要 WebSocket ? 了解计算 ...
- 转载 | Sublime text3 实用快捷键整理
实用快捷键 Ctrl+Shift+P:打开命令面板Ctrl+P:搜索项目中的文件Ctrl+G:跳转到第几行Ctrl+W:关闭当前打开文件Ctrl+Shift+W:关闭所有打开文件Ctrl+Shift+ ...
- memcached中hash表相关操作
以下转自http://blog.csdn.net/luotuo44/article/details/42773231 memcached源码中assoc.c文件里面的代码是构造一个哈希表.memc ...