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> ...
随机推荐
- android 8.0变更
Android 8.0 行为变更 Android 8.0 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 其中大部分变 ...
- [转] caffe激活层及参数
在激活层中,对输入数据进行激活操作(实际上就是一种函数变换),是逐元素进行运算的.从bottom得到一个blob数据输入,运算后,从top输入一个blob数据.在运算过程中,没有改变数据的大小,即输入 ...
- mapreduce的组件介绍
第一部分:重要的组件 Combiner •什么是Combiner •combine函数把一个map函数产生的<key,value>对(多个key, value)合并成一个新的<key ...
- TCxGrid 把列移上移下。
T
- 利用pt-table-checksum校验数据一致性
相信很多人的线上都搭建了MySQL主从这样的框架,很多人只监控MySQL的从服务器Slave_IO和Slave_SQL这两个线程是否为YES,还有 Seconds_Behind_Master延迟大不大 ...
- 微信小程序开发之IOS/Android兼容坑(持续更新)
一.时间转换问题: 这不只是小程序上面的问题是ios系统 都有这个问题就是new Date("2017-06-16") 在IOS会出现NAN的情况所以对于时间转换需要另行封装,解 ...
- 【Java】 遍历HashMap
1.遍历键值对 使用map.entrySet(),注意foreach语句中的类型为Map.Entry<K, V> 2.遍历Key 使用map.keySet() 3.遍历Value 使用ma ...
- 关于调用&&传址
关于调用&&传址//数组int d1[];Function(int *d){} int main(){Function(d1);} //指针int *p;Function(int *q ...
- 关于Sql Server的一些知识点的定义总结
数据库完整性:是指数据库中数据在逻辑上的一致性.正确性.有效性和相容性 实体完整性(Entity Integrity 行完整性):实体完整性指表中行的完整性.主要用于保证操作的数据(记录)非空.唯一 ...
- SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30001ms.
SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after ...