spoj1026Favorite Dice
题意翻译
一个n面的骰子,求期望掷几次能使得每一面都被掷到。
题目描述
BuggyD loves to carry his favorite die around. Perhaps you wonder why it's his favorite? Well, his die is magical and can be transformed into an N-sided unbiased die with the push of a button. Now BuggyD wants to learn more about his die, so he raises a question:
What is the expected number of throws of his die while it has N sides so that each number is rolled at least once?
输入输出格式
输入格式:
The first line of the input contains an integer t, the number of test cases. t test cases follow.
Each test case consists of a single line containing a single integer N (1 <= N <= 1000) - the number of sides on BuggyD's die.
输出格式:
For each test case, print one line containing the expected number of times BuggyD needs to throw his N-sided die so that each number appears at least once. The expected number must be accurate to 2 decimal digits.
输入输出样例
2
1
12
1.00
37.24 f [ i ]表示还剩i个面能把骰子的n面全扔一遍
对于扔一次骰子,有(n - i)/n能扔到剩下的面,有扔到之前扔过的面
f [ i ] = f [i + 1] * (( n - i ) / n ) + ( i / n) * f [ i ] + 1;
化简可得到f[i] = f [i + 1] + n/(n - i);(把f[ i ]挪到等式的一侧就可以了)
---------------------
作者:anonymity__
来源:CSDN
原文:https://blog.csdn.net/qq_42914224/article/details/83889581
版权声明:本文为博主原创文章,转载请附上博文链接!
代码是我自个的
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int t;
double f[];
int main()
{
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
memset(f,,sizeof(f));
f[n] = ;
for(int i = n - ;i >= ;i--)
{
f[i] = f[i + ] + n / (n - (double)i);
}
printf("%0.2lf\n",f[]);
}
return ;
}
spoj1026Favorite Dice的更多相关文章
- HDOJ 4652 Dice
期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 三种renderman规范引擎的dice对比
次表面做的有些烦躁,既然如此,索性先记一下前一阵比较的PIXIE.3delight.prman的dice方式. 研究过reyes的人都知道dice,简而言之,就是为了生成高质量高精度的图片(电影CG) ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 概率 Gym 100502D Dice Game
题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...
- HDU 5955 Guessing the Dice Roll
HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...
- UVALive 7275 Dice Cup (水题)
Dice Cup 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/D Description In many table-top ...
- HDU 4586 A - Play the Dice 找规律
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- CF Polycarpus' Dice (数学)
Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- 【kafka学习之六】kakfa消息生产、消费示例
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk1.8 kafka_2.11-0.11.0.0 zookeepe ...
- virtualenv的使用
virtualenv 是一个创建隔绝的Python环境的工具.在向服务器导入第三方库的时候特别有用. 1.首先,安装virtualenv pip install virtualenv 2.创建一个虚拟 ...
- CCF CSP 201712-1 最小差值
题目链接:http://118.190.20.162/view.page?gpid=T68 问题描述 试题编号: 201712-1 试题名称: 最小差值 时间限制: 1.0s 内存限制: 256.0M ...
- ABP入门系列之1——ABP总体介绍
ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应用程序的新起点, ...
- angular2 ----字符串、对象、base64 之间的转换
1. JSON对象转化为字符串 let obj = { "name":Ayinger; "sex":"女"; } let str = JSO ...
- 修改Vim内注释字体颜色
vim /etc/vimrc 然后按大写 G 到最后一行,插入 hi comment ctermfg=6 wq保存退出 PS:默认的注释颜色是4 然后有0,1,2,3,4,5 ...
- ensp 单臂路由实验
搭建如下拓扑 交换机: 创建vlan10 20 g0/0/1接口设置访问类型为access,加入到vlan10:g0/0/2接口设置访问类型为access,加入到vlan20 g0/0/3接口设置为t ...
- Bugku-CTF之备份是个好习惯
Day17 备份是个好习惯 听说备份是个好习惯 http://123.206.87.240:8002/web16/
- 除了使用new关键字,还有什么方法可以创建Java对象呢?
今天来盘点一下除了使用 "new" 关键字创建对象,还有什么方法可以创建Java对象呢? 因为是创建对象,所以这里ioc容器不在范围内 我们先看一下常用的new关键字创建 Clas ...
- js函数式编程curry与compose实现
//自行实现以下curry函数和compose //curry function curry(fn) { return function aa (...arg) { if (arg.length &g ...