codeforces Round #259(div2) C解题报告
1 second
256 megabytes
standard input
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.
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
题目大意:
一个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解题报告的更多相关文章
- codeforces Round #258(div2) D解题报告
D. Count Good Substrings time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces Round #259(div2) E解决报告
E. Little Pony and Summer Sun Celebration time limit per test 1 second memory limit per test 256 meg ...
- codeforces Round #258(div2) C解题报告
C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- codeforces Round #259(div2) D解决报告
D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes i ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #380 (Div. 2) 解题报告
第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- Codeforces Round #277 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...
随机推荐
- javaweb笔记四
得到表单数据:1.String str = request.getParameter(String)//根据表单名得到表单值,如果是多个同名的键值,返回第一个值.2.String[] str= req ...
- AngularJs(SPA)单页面SEO以及百度统计应用(下)
苍苍之天不得久视,堂堂之地不得久履 当你小心翼翼的开启服务端渲染的同时,一个问题不得不注意,使用内存模式去保存渲染过的页面,这样服务断掉重启后,缓存也没有了,所以这里我们使用mongdodb进行本地化 ...
- 使用 JavaScript 编写优化算法 (1)
之前一直用Python来写优化算法,为了增强 JS 的熟练程度,开始将原有的代码改写成 JS.采用的工具包括 node.js + Grunt + nodeunit + github + npm + t ...
- Android Studio 3.0正式版填坑之路
原文:https://www.jianshu.com/p/9b25087a5d7d Android Studio 3.0启动图 序言 总看别人的文章,今天尝试着自己来写一篇.在逛论坛时候,无意间发 ...
- 【LOJ】#2496. 「AHOI / HNOI2018」毒瘤
题面 还有这么诚实的出题人! 我们最多影响20个点,然后把这20个点的虚树建出来,并且枚举每个点的选举状态,如果一个点选或不选可以通过改\(dp[u][0] = 0\)或\(dp[u][1] = 0\ ...
- android弹出对话框
我们在平时做开发的时候,免不了会用到各种各样的对话框,相信有过其他平台开发经验的朋友都会知道,大部分的平台都只提供了几个最简单的实现,如果我们想实现自己特定需求的对话框,大家可能首先会想到,通过继承等 ...
- [ 转载 ] get和post的区别
GET和POST两种基本请求方法的区别 GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二. 最直观的区别就是GET把参数包含在URL中,POST通过r ...
- Redis学习笔记(1)- CentOS 6.4 安装Redis
Redis学习笔记(1)- CentOS 6.4 安装Redis 2013.10.13 学习环境 vm 10.1 + 默认.新装的干净 CentOS 6.4 64BIT系统 准备 1 ...
- 使用JAXB实现Bean与Xml相互转换
最近几天,我自己负责的应用这边引入了一个新的合作方,主要是我这边调用他们的接口,但是有个很坑的地方,他们传参居然不支持json格式,并且只支持xml格式进行交互,于是自己写了一个工具类去支持bean与 ...
- android 上下边框线
<!-- 连框颜色值 --> <item> <shape> <solid android:color="@android:color/backgro ...