CSU-ACM暑假集训基础组训练赛(5-1) B - Problem B
2014-08-11 15:55
381 查看
B - Problem B
Time Limit:2000MS Memory Limit:0KB 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.
Sample Input
<script type="text/javascript"> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
题目大意:
一个有n面的色子抛掷多少次能使所有面都能被抛到过,求期望值
总面数为n,当已经抛到过 i 个不同面时,我们抛出下一个不同面的概率为 (n-i)/n,那么抛的次数为 n/(n-i),
将所有抛出下个面的次数累加起来就好了
简单的模拟题,前提是读懂题意。代码:
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t,i,n;
scanf("%d",&t);
while(t--)
{
double s=0.0;
scanf("%d",&n);
for(i=0;i<n;i++)
s+=double(n)/double(n-i);
printf("%.2lf\n",s);
}
return 0;
}
总结:好好学习,天天向上。聪哥说:不会只能怪高中老师了~~~
Time Limit:2000MS Memory Limit:0KB 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.
Sample Input
Input: 2 1 12 Output: 1.00 37.24
<script type="text/javascript"> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
题目大意:
一个有n面的色子抛掷多少次能使所有面都能被抛到过,求期望值
总面数为n,当已经抛到过 i 个不同面时,我们抛出下一个不同面的概率为 (n-i)/n,那么抛的次数为 n/(n-i),
将所有抛出下个面的次数累加起来就好了
简单的模拟题,前提是读懂题意。代码:
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t,i,n;
scanf("%d",&t);
while(t--)
{
double s=0.0;
scanf("%d",&n);
for(i=0;i<n;i++)
s+=double(n)/double(n-i);
printf("%.2lf\n",s);
}
return 0;
}
总结:好好学习,天天向上。聪哥说:不会只能怪高中老师了~~~
相关文章推荐
- CSU-ACM暑假集训基础组训练赛(2) B - Problem B
- CSU-ACM暑假集训基础组训练赛(1) B - Problem B
- CSU-ACM暑假集训基础组训练赛(5-1) C - Problem C
- CSU-ACM2014暑假集训基础组训练赛(1) 解题报告
- CSU-ACM暑假集训基础组训练赛(1) A - Problem A
- CSU-ACM暑假集训基础组训练赛(2) D - Problem D
- CSU-ACM暑假集训基础组训练赛(4)解题报告
- CSU-ACM暑假集训基础组训练赛(5-1) A - Problem A
- CSU-ACM暑假集训基础组训练赛(2) 解题报告
- CSU-ACM暑假集训基础组七夕专场 F - Problem F
- CSU-ACM暑假集训基础组七夕专场
- CSU-ACM暑假集训基础组七夕专场 D - Problem D
- CSU-ACM暑假集训训练1(二分 2015/7/21)
- CSU--------2133: 中南大学2017年ACM暑期集训前期训练题集(基础题)
- 【ECJTU_ACM 11级队员2012年暑假训练赛(7)】
- 【ECJTU_ACM 11级队员2012年暑假训练赛(7) - D - Little Elephant and Rozdil】
- 【ECJTU_ACM 11级队员2012年暑假训练赛(7) - I - Snow】
- 【ECJTU_ACM 11级队员2012年暑假训练赛(7) - H - Bookshelf 2】
- 【ECJTU_ACM 11级队员2012年暑假训练赛(7) - G - Prime Sum】
- 【ECJTU_ACM 11级队员2012年暑假训练赛(8) - B - Modular Inverse】