题意翻译

一个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. 2018-2019-2 网络对抗技术 20165335 Exp4 恶意代码分析

    实验内容: 一.使用schtacks进行系统运行监控,使用sysmon工具监控系统的具体进程,使用各种工具进行监控,并针对软件的启动回连,安装到目标机,以及其他的控制行为的分析,同时,对主机的注册表, ...

  2. postgresql 表触发器

    1.先建一个函数,用来执行触发器启动后要执行的脚本 CREATE OR REPLACE FUNCTION "public"."trigger_day_aqi"( ...

  3. oracle密码过期问题解决

    1.查看open用户 select username,account_status,expiry_date,profile from dba_users; 2.查看目前密码过期策略 select * ...

  4. yum仓库源搭建

    本地yum源搭建 cd源 mount /dev/sr0 /mnt vim  /etc/yum.repos.d/base.repo [centos-base]name=centos7#baseurl=f ...

  5. [dart学习]第三篇:dart变量介绍 (二)

    本篇继续介绍dart变量类型,可参考前文:第二篇:dart变量介绍 (一) (一)final和const类型 如果你不打算修改一个变量的值,那么就把它定义为final或const类型.其中:final ...

  6. 自娱自乐RN版小说APP历程记录

    当前rn版本 "react": "16.6.3" "react-native": "0.58.5" 通过react-na ...

  7. 2019/4/15 wen 正则表达式

  8. vue 添加旋转图片 修改css transform 值

    //点击放大图片并旋转图片 conponents组建 <template>    <!-- 过渡动画 -->    <transition name="fade ...

  9. Tomcat每日报错

    本次针对tomcat端口占用所产生的8080:8009:8000报错 1.打开CMD命令提示符(win+R). 2.输入指令netstat str -ano|findstr 8080(8080这里可以 ...

  10. Android 全局使用第三方字体

    给APP全局设置字体主要分为两个方面来介绍 一.给原生界面设置第三方字体 1.准备工作-下载第三方字体:传送门 将文件放入工程assets目录下.(一般个人习惯单独命名一个文件夹放字体文件,也可直接放 ...