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> ...
随机推荐
- python小记
最近有匹骚猪用微信骚扰我,我很是气愤, 自学一波脚本: 学习目的:用脚本回击回去,通过py写一个脚本,一次性给别人发n条消息: mac上自学python: brew install python3(自 ...
- Coursera台大机器学习技法课程笔记14-Radial Basis Function Network
将Radial Basis Function与Network相结合.实际上衡量两个点的相似性:距离越近,值越大. 将神经元换为与距离有关的函数,就是RBF Network: 可以用kernel和RBF ...
- csu 1982:小M的移动硬盘(双向链表)
Description 最近小M买了一个移动硬盘来储存自己电脑里不常用的文件.但是他把这些文件一股脑丢进移动硬盘后,觉得这些文件似乎没有被很好地归类,这样以后找起来岂不是会非常麻烦? 小M最终决定要把 ...
- activeMQ安全配置及常见问题解决
https://blog.csdn.net/dandan2zhuzhu/article/details/78461872
- Codeforces 379F New Year Tree 树的直径的性质推理
New Year Tree 我们假设当前的直径两端为A, B, 那么现在加入v的两个儿子x, y. 求直径的话我们可以第一次dfs找到最远点这个点必定为直径上的点, 然而用这个点第二次dfs找到最远点 ...
- MySQL子查询,派生表和通用表达式
一:子查询 1.介绍 在另一个查询(外部查询)中嵌套另一个查询语句(内部查询),并使用内部查询的结果值作为外部查询条件. 2.子查询在where中 SELECT customerNumber, che ...
- rabbitmq学习(五) —— 路由
绑定(Bindings) 在上一个教程中,我们已经使用过绑定.你可能会记得如下代码: channel.queueBind(queueName, EXCHANGE_NAME, "") ...
- csdn 音乐 怎么拦截 提交后的程序 csdn 栏目 音乐 csdn 添加 音乐
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha csdn 栏目 音乐 csdn 添加 音乐 ======= <embed src= ...
- BZOJ.4695.最假女选手(线段树 Segment tree Beats!)
题目链接 区间取\(\max,\ \min\)并维护区间和是普通线段树无法处理的. 对于操作二,维护区间最小值\(mn\).最小值个数\(t\).严格次小值\(se\). 当\(mn\geq x\)时 ...
- BZOJ.1576.[Usaco2009 Jan]安全路经Travel(树形DP 并查集)
题目链接 BZOJ 洛谷 先求最短路树.考虑每一条非树边(u,v,len),设w=LCA(u,v),这条边会对w->v上的点x(x!=w)有dis[u]+dis[v]-dis[x]+len的距离 ...