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 ...
随机推荐
- Web容器启动中执行某个Java类
1.监听(Listener) <!-- 配置监听 --> <listener> <listener-class>com.xian.jdbc.GetPropertie ...
- StarUML 3.0 破解方法
首先在我这里下载 StarUML3.0 破解替换文件app.asar 链接:https://pan.baidu.com/s/1wDMKDQkKrE9D1c0YeXz0xg 密码:y65m 然后参照下 ...
- 荔枝FM前端面试题
最近接到了荔枝FM的面试通知,遗憾的是没有拿到offer,但是这次面试呢,还是收获很大的,下面就来给大家说说我遇到的面试题 一面 一面是直接发了一套面试题到邮箱,开启了防作弊的,限时20分钟做完,下面 ...
- 小X的逆袭
[问题描述]毕业于普通本科的小x 一直自称是资深屌丝.谁又能想到,如此不起眼的小x 在历经重重面试环节后,竟然如愿以偿加入了心仪已久的腾讯公司!正所谓野百合也有春天,屌丝也有逆袭的那一天!一段时间以后 ...
- SpringBoot:Web开发
西部开源-秦疆老师:基于SpringBoot 2.1.6 的博客教程 , 基于atguigu 1.5.x 视频优化 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处 ...
- 初识JavaScript和面向对象
1.javascript基本数据类型: number: 数值类型 string: 字符串类型 boolean: 布尔类型 null: 空类型 undefault:未定义类型 object: 基本数据类 ...
- 【0726 | Day 2】编程语言分类/主流编程语言介绍/网络的瓶颈效应
编程语言分类 机器语言 与硬件交互 优点:执行效率高 缺点:开发效率低 汇编语言 间接与硬件交互 优点(相较于机器语言):开发效率高 缺点(相较于机器语言):执行效率低 高级语言 简单化指令,让人人都 ...
- Java一个简单的文件工具集
class FileUtils { //文件目录下文件总数目 public static int fileNumber(File dir) { int filenumber = 0; if(dir.e ...
- mybatis批量更新策略
我们知道循环中操作db会导致连接数满,严重影响数据库性能.所以在对db进行DQL与DML时,根据业务逻辑尽量批量操作,这里我们介绍下使用mybatis批量更新mysql的两种方式. 方式一: < ...
- Spring中的属性编辑器的使用
Spring中的属性编辑器的使用 转载自 http://blog.sina.com.cn/s/blog_59ca2c2a0100jxwh.html Struts中用一个类型转换器,在Spring中也有 ...