题意翻译

一个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.

输入输出样例

输入样例#1: 复制

2
1
12
输出样例#1: 复制

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的更多相关文章

  1. HDOJ 4652 Dice

      期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. 三种renderman规范引擎的dice对比

    次表面做的有些烦躁,既然如此,索性先记一下前一阵比较的PIXIE.3delight.prman的dice方式. 研究过reyes的人都知道dice,简而言之,就是为了生成高质量高精度的图片(电影CG) ...

  3. LightOJ 1248 Dice (III) 概率

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  4. hdu 4586 Play the Dice 概率推导题

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  5. 概率 Gym 100502D Dice Game

    题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...

  6. HDU 5955 Guessing the Dice Roll

    HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...

  7. UVALive 7275 Dice Cup (水题)

    Dice Cup 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/D Description In many table-top ...

  8. HDU 4586 A - Play the Dice 找规律

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. CF Polycarpus' Dice (数学)

    Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. 信步漫谈之Redis—Linux下环境搭建

    一.环境 Linux 系统:Suse11(SLES-11-SP3-DVD-x86_64-GM-DVD1)Redis 安装包:redis-4.0.11.tar.gz      下载地址:http://d ...

  2. CCF CSP 201503-1 图像旋转 (降维)

    题目链接:http://118.190.20.162/view.page?gpid=T27 问题描述 试题编号: 201503-1 试题名称: 图像旋转 时间限制: 5.0s 内存限制: 256.0M ...

  3. 《CSS世界》读书笔记(十四)

    <!--  <CSS世界>张鑫旭著 --> 功勋卓越的 border 属性 border-width 不支持百分比值 border-style 类型 border-style ...

  4. 画多边形form并填充背景色(可以实现圆角边框 有锯齿)

    public Form1() { InitializeComponent(); this.BackColor = ColorTranslator.FromHtml("#F7F1F1" ...

  5. 论使用HashMap优化双层For循环的实际性能

    当需要对两个集合进行相互操作的时候,一般需要进行双层For循环,但我们知道双层For在数量越大的时候性能影响越大 这时候我们会想到的其中一种解决方法就是利用Hashmap在查找数据的高效上来优化双层F ...

  6. kubernetes容器删除时快速释放ip的方案

    问题的来由 在kubernetes集群的生产中,经常遇到这样的一个问题,就是在应用大规模更新时,大量容器删除而后大量容器创建,创建的容器需要很长时间才能就绪.这其中一个可能的原因,就是大量容器删除释放 ...

  7. Haystack全文检索

    1.什么是Haystack Haystack是django的开源全文搜索框架(全文检索不同于特定字段的模糊查询,使用全文检索的效率更高 ),该框架支持Solr,Elasticsearch(java写的 ...

  8. 本地Git仓库和Github仓库的关联

    1.我们首先创建一个文件夹(用于保存本地仓) 在我们想要创建的路径下右键鼠标打开Git Bash Here(创建一个文件夹,并进入文件夹) 2.通过命令git init把我们刚才创建的文件夹变成Git ...

  9. 实现点击页面其他地方,隐藏div(原生和VUE)

    1原生方法 // html <div id="box" style="width:110px;height:110px;background-color:red&q ...

  10. sql取整数

    [四舍五入取整]select round(1.1,0) 执行结果为1: [向下取整]select floor(1.1) 执行结果为2: [向上取整] select ceiling(1.1) 执行结果为 ...