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.
A single line contains two integers m and n (1 ≤ m, n ≤ 105).
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.
6 1
3.500000000000
6 3
4.958333333333
2 2
1.750000000000
Consider the third test example. If you've made two tosses:
- You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
- You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
- You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
- 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
题意:
给出 n,m(1 ~ 10 ^ 5),代表有一个 n 面的骰子,将这个骰子扔 m 次,求最大值的期望值。
思路:
数学。概率。一共出现的事件总数是 n ^ m,故每一次出现可能的概率都是 1 / ( n ^ m ) ,每一次可能的事件都会出现一个最大值 k,把所有 k 的总数加和起来乘以 1 / ( n ^ m )就是答案。故问题转化为求 k 的总数。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int main() { int m, n; scanf("%d%d", &m, &n); double ans = 0; for (int i = 1; i <= m; ++i) { ans += i * (pow((double)i / m, n) - pow((double)(i - 1) / m, n)); } printf("%.12f\n", ans); return 0; }
相关推荐
通过安装带有My Little Pony系列美丽壁纸的扩展程序,可以使您的浏览器更加有趣和丰富多彩。 每次打开这些主题时,这些主题都会显示在新标签页上,因此,您将始终可以欣赏它们。 不要忘记,您随时可以在它们之间切换...
您将在每个新选项卡中打开“我的小马驹友谊就是魔法”高清图像! 惊人的! ==很棒的高品质我的小马驹友谊在每个新标签页中都是神奇的影像。 ==对于真正的粉丝,就像我一样:)您会受到很大启发,并且会喜欢这个不错...
MLP-FiM 主题游戏,使用 Blender 游戏引擎。 由 CreatorOfPony 从 My Little Pony 开源分叉出来。
准备好享受我的小马驹壁纸 准备好享受“我的小马驹”高质量图片和其他高级功能的广阔世界! 每次打开新选项卡时,安装我的小马驹高清壁纸主题,并享受各种高清壁纸。 无论您是在家中PC之前还是在办公室中工作,都...
Pony对QQMail的邮件摘录Pony对QQMail的邮件摘录
博文http://blog.csdn.net/chocolateloveme/article/details/12658429
Pony 是开源,actor模型,功能安全,高性能的编程语言
BronyCenter-社交网站 请不要使用此代码! 这确实很糟糕,不安全且有故障。 我正在恢复这个项目,只是为了在这里修复一些问题,而我仍在学习真正的OOP,MVC设计模式等等。 当我准备好时,它将被重写。
cartoon_pony019
“用户体验”(UX)设计这个术语可能令人困惑的原因之一是,从本质上说,所有的设计原则都应该是针对他们所设计的用户的体验。无论是一个金属螺栓,一个印刷的音乐会程序,还是一台计算机,每一个设计好的对象都有一...
buy_my_pony
Pony是Python的一种ORM,它允许使用生成器表达式来构造查询,通过将生成器表达式的抽象语法树解析成SQL语句。它也有在线ER图编辑器可以帮助你创建Model。 示例分析 Pony语句: select(p for p in Person if p.age >...
一个用 Pony 编写的文字冒险游戏,作为一种学习练习,可以让您更加熟悉该语言并用作各种语言概念的插图。在所有可能的情况下,PonyMUD 的目标是利用 Actor 模型和完全异步处理的力量。
buy_my_pony017
cartoon_pony
小马Pony是一种开源的,面向对象的,参与者模型,功能安全的高性能编程语言。状态Pony仍为1.0之前的版本,因此半定期引入重大更改。 这些更改通常很容易适应。 用Pony编写的应用程序当前在生产环境中使用。支持平台...
pony-jason:Pony语言的JSON库,已针对灵活性和性能进行了调整