博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)
阅读量:5260 次
发布时间:2019-06-14

本文共 2452 字,大约阅读时间需要 8 分钟。

A. Little Pony and Expected Maximum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 mdots. 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.

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.

Examples
input
6 1
output
3.500000000000
input
6 3
output
4.958333333333
input
2 2
output
1.750000000000
Note

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

 

 

【分析】

  【一开始打了一个DP。。f[i]表示弄了i次的期望然后转移】

  【第二个样例就错了】

  ↑不要说你学过概率好么?

  好吧,清醒之后就知道,枚举最大值,然后算最大值是i的概率,是$i^n-(i-1)^n$,算一个小容斥吧,要求一定含一个i嘛。。

  累加就好了。

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 #define Maxn 100010 9 10 double qpow(double x,int b)11 {12 double ans=1;13 while(b)14 {15 if(b&1) ans=ans*x;16 x=x*x;17 b>>=1;18 }19 return ans;20 }21 22 int main()23 {24 int m,n;25 scanf("%d%d",&m,&n);26 double ans=0;27 for(int i=1;i<=m;i++)28 {29 ans+=i*(qpow(1.0*i/m,n)-qpow(1.0*(i-1)/m,n));30 }31 printf("%.5lf\n",ans);32 return 0;33 }
View Code

 

2017-04-21 19:44:52

转载于:https://www.cnblogs.com/Konjakmoyu/p/6745201.html

你可能感兴趣的文章
Python学习(七)面向对象 ——继承和多态
查看>>
C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 客户端多网络支持
查看>>
阴影:box_shadow
查看>>
HDU 4122
查看>>
Suite3.4.7和Keil u3自带fx2.h、fx2regs.h文件的异同
查看>>
盖德化工网采集1
查看>>
算法优点和缺点汇总(推荐AAA)
查看>>
图解javascript this指向什么?
查看>>
JS正则表达式将url转成json格式
查看>>
ios uiwebview 上几个技巧
查看>>
C#更改控制台文本的前景色和背景色
查看>>
比对两个同类型的List
查看>>
Falsk_day01
查看>>
JQuery 加载 CSS、JS 文件
查看>>
数据结构(七)排序---希尔排序
查看>>
webkit 渲染机制
查看>>
数据结构(五)图---最小生成树(普里姆算法)
查看>>
Linux下./configure && make && make install 编译安装和卸载
查看>>
iOS-Senior17-UIView动画
查看>>
#undef
查看>>