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

Sample test(s)
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

题目大意:

一个m个面的骰子。抛掷n次,求这n次里最大值的期望是多少。

解法:

数学题,有m个面的骰子。抛n次,那么总共的情况就有m^n。

我们从m=1開始推起。

m = 1, 仅仅有一种情况。

m = 2。新增了2^n-1^n种情况。这些新增的情况里面。最大值均是 2,

m = 3,新增了3^n-2^n种情况。这些新增的情况里面,最大值均是 3。

我们就能够推出数学期望公式:  ans = 1/(m^n) * [1 + (2^n-1^n)*2 + (3^n-2^n)*3 .... + (m^n - (m-1)^n)*m]

但m^n太大,我们得改变一下式子。 ans = (1/m)^n - (0/m)^n + [(2/m)^n - (1/m)^n] * 2 ...... + [(m/m)^n - ((m-1)/m)^n] * m。

代码:

#include <cstdio>
#include <cmath> using namespace std; double n, m, ans; int main() {
scanf("%lf%lf", &m, &n); ans = pow(1.0/m, n);
for (int i = 2; i <= m; i++)
ans += (pow(i/m, n) - pow((i-1)/m, n)) * i;
printf("%lf", ans);
}

codeforces Round #259(div2) C解题报告的更多相关文章

  1. codeforces Round #258(div2) D解题报告

    D. Count Good Substrings time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. codeforces Round #259(div2) E解决报告

    E. Little Pony and Summer Sun Celebration time limit per test 1 second memory limit per test 256 meg ...

  3. codeforces Round #258(div2) C解题报告

    C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  4. codeforces Round #259(div2) D解决报告

    D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes i ...

  5. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  6. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  7. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  8. Codeforces Round #281 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...

  9. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

随机推荐

  1. idea导入maven项目,包没有自动下载

    解决办法: 先把这里面的全部删掉 然后在pom.xml里面右键 这样就会重新下载包

  2. 【转】使用TCP协议连续传输大量数据时,是否会丢包,应如何避免?

    使用TCP协议连续传输大量数据时,是否会丢包,应如何避免? 比如发送文件.记得有人提过可能会发生什么堆栈溢出.怎样避免呢?是不是可以收到数据后发送确认包,收到确认包后再继续发送.或是发送方发送了一些数 ...

  3. Fiddler 常用功能总结

    1.fiddler相关配置   2.如何抓包 移动端 ①保持手机和电脑处于同一网络中 ②设置手机的代理为电脑当前所处网络的IP,端口号为:8888,eg:10.12.1.64:8888. ③ 启动ap ...

  4. 【军哥谈CI框架】之CI中集成百度UEditor

    Hello,各位亲,新的一周来临啦,很高兴这么快又跟大家伙见面!话说上一回,军哥带大家用JQuery写了一个城市级联菜单的例子 ,不知道亲们学会了多少,是否自己可以独立写出来了呢. 军哥很是期待大家学 ...

  5. hdu 1232 变成生成树至少还要加几条边 (并查集模板题)

    求一个图 变成生成树至少还要加几条边(成环的边要删掉,但不用统计) Sample Input4 2 //n m1 3//u v4 33 31 21 32 35 21 23 5999 00 Sample ...

  6. 兼容到ie10的js文件导出、下载到本地

    话不多说,上代码: try { let reader = new FileReader(); let blob = new Blob([res.data], { type: 'application/ ...

  7. linux {..}用法

    一.2018-{01..07}* 这个意思是 2018-01*   到2018-07*全部输出出来. 二.echo {a..c} a b c

  8. spark web ui中的skipped的含义

    顾名思义,跳出的意思啦. 例如如图: skipped的stages代表是已经执行过了.所以不需要再执行了. 如何,你有一个 testRdd.然后先做 testRdd.Filter("xxx& ...

  9. SpringBoot的搭建

    一:搭建 1.环境要求 Java7及以上 Spring Framework4.1.5及以上 2.新建一个maven工程 3.pom.xml(生成) <!-- 必须引入spring-parent, ...

  10. 001.SMB简介

    一 简介 samba基于NetBIOS协议开发,能和windows通信,但只能在局域网通信. 二 Samba主要应用 文件共享 打印服务器 Samba登录时身份验证 进行windows主机名解析 三 ...