SPOJ FAVDICE
来源:互联网 发布:北京数据 编辑:程序博客网 时间:2024/06/10 02:28
Description
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?
Input
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.
Output
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.
Example
Input:2112Output:1.0037.24
概率题。
n/1+n/2+....+n/n;
#include <stdio.h>int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); double sum=0; for(int i=1;i<=n;i++) sum+=(double)n/i; printf("%.2lf\n",sum); } return 0;}
另一种期望DP的做法。
#include <cstdio>#include <cstring>using namespace std;#define N 1005double dp[N];int main(){ int T,k,n; scanf("%d",&T); while(T--) { scanf("%d%d",&k,&n); dp[1]=1.00; for(int i=2;i<=n;i++) dp[i]=dp[i-1]+(k-dp[i-1])/k; printf("%.5f\n",dp[n]); } return 0;}
- SPOJ FAVDICE
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- 选择排序
- 设置文本排序及对齐
- 指针常量和常量指针
- 页面的跳转
- Ubuntu server 15.0.4安装Redis
- SPOJ FAVDICE
- Codeforces Round #256 (Div. 2) B. Suffix Structures
- SSH框架总结-框架分析
- 欢迎使用CSDN-markdown编辑器
- json 在线转换
- HBuilder快捷键
- POJ1845------Sumdiv
- jdbc事务处理
- 验证签名机制——java示例