CodeForces 453A Little Pony and Expected Maximum

来源:互联网 发布:软件测评师证 编辑:程序博客网 时间:2024/06/11 22:51
E - Little Pony and Expected Maximum
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 453A
Appoint description: 

Description

Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.

The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains m dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.

你有一个m面的骰子,分别标号为1~ m,任意掷一次骰子,掷到每一面的概率均为1/m。
现求任意掷n次骰子,你的得分为n次掷到数字的最大值。求你的期望得分。

Input

A single line contains two integers m and n (1 ≤ m, n ≤ 105).

Output

Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10  - 4.

Sample Input

Input
6 1
Output
3.500000000000
Input
6 3
Output
4.958333333333
Input
2 2
Output
1.750000000000

Hint

Consider the third test example. If you've made two tosses:

  1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
  2. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
  3. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
  4. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.

The probability of each outcome is 0.25, that is expectation equals to:

You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

按照第二组样例,M = 6, N = 3

那么如果扔到的最大点数是是1, 那么只有一种情况 即 1 1 1

如果扔到的最大点数是2 那么可能是 1 1 2, 1 2 1,.......每个位置都只能有1和2两种可能(不然最大点数就不是2了),但是要减去所有都是1的情况,所以最大点数是2的情况为2^n-1^n。

因为总的种数是m^n次。所以概率就是(2^n-1^n)/m^n,那么递推一下就可以了。


扔的最大点为k的概率k^n/m^n-(k-1)^n/m^n;

<span style="background-color: rgb(255, 255, 255);">#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;int main(){int n,m,i;while(scanf("%d%d",&m,&n)!=EOF){double sum=0.0;double pre=0.0;for(i=1;i<=m;i++){double now=pow((double(i)/double(m)),double(n));sum+=(now-pre)*i;pre=now;}printf("%.12lf\n",sum);}return 0;}</span>


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在国外没有钱了怎么办 被劫持为人质怎么办 在印度签证过期怎么办 办签证被拒怎么办 澳洲留学生怎么办新加坡签证 韩国交换生签证怎么办 没有钱还贷款怎么办 英国主动退学后怎么办 英国留学被劝退怎么办 英国留学签证被拒怎么办 签证纸丢了怎么办 日本的探亲签证怎么办 成都去港澳怎么办签证 在北京怎么办泰国签证 法院判决不准离婚怎么办 再婚小孩上户口怎么办 被供应商起诉了怎么办 离婚案原告撤诉怎么办 离婚起诉不到场怎么办 判决书判了败诉怎么办 对执行裁定不服怎么办 贴吧尺寸超限怎么办 usbkey密码忘了怎么办 农信房贷逾期几个小时怎么办 广东农信房贷逾期一天怎么办 三亚的房太潮了怎么办 没高中档案积分怎么办 临牌过期了怎么办 居住证凭证丢了怎么办 上海市居住证过期了怎么办 上海居住证积分不够怎么办 居住证登录密码忘记怎么办 投靠中考上海居住证怎么办 嫁入广州户口怎么办 上海积分扣完了怎么办 公立小学积分不够怎么办 查不到户口信息怎么办 小孩上不到户口怎么办 离开上海上海户口怎么办? 上海没房户口怎么办 没有房照动迁怎么办