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 ...
随机推荐
- jenkins构建任务后发送邮件
1.jenkins登录后-系统管理-系统设置打开后定位到下面的位置:系统管理员邮件地址一定要填写 2.下滑页面定位到extend E-mail Notification:这个是jenkins的一个插件 ...
- Flask实战-留言板-使用Faker生成虚拟数据
使用Faker生成虚拟数据 创建虚拟数据是编写Web程序时的常见需求.在简单的场景下,我们可以手动创建一些虚拟数据,但更方便的选择是使用第三方库实现.流行的python虚拟数据生成工具有Mimesis ...
- PHP中文转拼音
网上大都讲的,都不支持繁体字,毕竟就是一个函数解决的事. 推荐一个很好的扩展,github地址: https://github.com/overtrue/pinyin 怎么用,自己去看就行了.
- 算法(第四版)C# 习题题解——2.3
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 查找更为方便的版本见:http ...
- CentOS 离线安装 MYSQL+APACHE+PHP
一.MYSQL安装 下载MYSQL安装包:MySQL-client-XXX.rpm MySQL-server-XXX.rpm MySQL-devel-XXX.rpm 如有冲突,要先删除原来的M ...
- 字符和字符串在Java中的旅程
以下是个人对java中字符和字符串的见解,如有疏漏之处,还请不吝赐教. 下面通过一个简单的程序来说明字符和字符串在Java中的旅程. 以字符 ' 中 '为例, 它的GBK编码是2个字节:0xd6d0, ...
- Java 基础知识点小结
小知识点 所有的程序,都要定义在类里面: 异常 定义方法时,使用 throws 可以用来捕获方法体内没有捕获的异常,然后以 SomeException 抛出异常 java是解释型语言.java虚拟机能 ...
- webform运行时弹出JavaScript的alert窗口
https://stackoverflow.com/questions/9720143/asp-net-web-application-message-box Or create a method l ...
- (转)Extracting knowledge from knowledge graphs using Facebook Pytorch BigGraph.
Extracting knowledge from knowledge graphs using Facebook Pytorch BigGraph 2019-04-27 09:33:58 This ...
- VS Code插件配置
常用 VS Code 插件: Auto Import 有了这个插件,就不需要再手动引入文件了.如果是基于组件的项目,直接输入组件名插件会自动处理 imported. ** Add jsdoc comm ...