SPOJ FAVDICE
2015-08-20 15:18
471 查看
E - E
Time Limit:391MS Memory Limit:1572864KB 64bit IO Format:%lld
& %llu
Submit Status Practice SPOJ
FAVDICE
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?
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.
概率题。
n/1+n/2+....+n/n;
另一种期望DP的做法。
Time Limit:391MS Memory Limit:1572864KB 64bit IO Format:%lld
& %llu
Submit Status Practice SPOJ
FAVDICE
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: 2 1 12 Output: 1.00 37.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 1005 double dp ; 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 ); } return 0; }
相关文章推荐
- linux下搭建gsoap环境
- PL/SQL之游标的使用
- Hbuilder检测不到真机的解决方法
- slickgird链接
- Gamebryo 游戏引擎分析(二)内存管理
- Powershell Module for Netapp Data Ontap
- Powershell Module for Netapp Data Ontap
- ajax 中根据json数据不同 对页面中 选择框radio 进行动态选择
- exchange2013的搜索邮件跟踪日志功能
- Rtmpdump
- Android中内容观察者的使用---- ContentObserver类详解
- 自定义控件 实现文本框输入模仿下拉框选择功能
- 操作系统原理——(线程相关)
- [Leetcode] maximum gap
- 字符串匹配的KMP算法
- iOS循环引用
- array_multisort — 对多个数组或多维数组进行排序
- Apple Watch和机械手表的纠结
- Minimum Path Sum
- JFrame实现圆角窗体