【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)
A. Little Pony and Expected Maximumtime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputA single line contains two integers m and n (1 ≤ m, n ≤ 105).
OutputOutput 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.
Examplesinput6 1output3.500000000000input6 3output4.958333333333input2 2output1.750000000000NoteConsider 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
【分析】
【一开始打了一个DP。。f[i]表示弄了i次的期望然后转移】
【第二个样例就错了】
↑不要说你学过概率好么?
好吧,清醒之后就知道,枚举最大值,然后算最大值是i的概率,是$i^n-(i-1)^n$,算一个小容斥吧,要求一定含一个i嘛。。
累加就好了。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define Maxn 100010 double qpow(double x,int b)
{
double ans=;
while(b)
{
if(b&) ans=ans*x;
x=x*x;
b>>=;
}
return ans;
} int main()
{
int m,n;
scanf("%d%d",&m,&n);
double ans=;
for(int i=;i<=m;i++)
{
ans+=i*(qpow(1.0*i/m,n)-qpow(1.0*(i-)/m,n));
}
printf("%.5lf\n",ans);
return ;
}
2017-04-21 19:44:52
【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)的更多相关文章
- CF453A Little Pony and Expected Maximum 期望dp
LINK:Little Pony and Expected Maximum 容易设出状态f[i][j]表示前i次最大值为j的概率. 转移很显然 不过复杂度很高. 考虑优化.考虑直接求出最大值为j的概率 ...
- 嘴巴题9 Codeforces 453A. Little Pony and Expected Maximum
A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...
- CodeForces 454C Little Pony and Expected Maximum
Little Pony and Expected Maximum Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I6 ...
- Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)
题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...
- Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题
A. Little Pony and Expected Maximum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...
- E. Little Pony and Expected Maximum(组合期望)
题目描述: Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megaby ...
- A. Little Pony and Expected Maximum
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she ...
- CF - 392 C. Yet Another Number Sequence (矩阵快速幂)
CF - 392 C. Yet Another Number Sequence 题目传送门 这个题看了十几分钟直接看题解了,然后恍然大悟,发现纸笔难于描述于是乎用Tex把初始矩阵以及转移矩阵都敲了出来 ...
- cf 453A.Little Pony and Expected Maximum
水了一上午.. 拿6面举例子吧,因为是投掷m次取最大,最大是1概率(1/6)^m;最大是2就可以取到(1,2)那么概率就是(1/3)^m-(1/6)^m.(当前减去上一个) #include<b ...
随机推荐
- Ubuntu 14.04 + xRDP + Xfce 实现Windows远程桌面连接
1. 安装xRDP及vncserver sudo apt-get install xrdp sudo apt-get install vnc4server tightvncserver 2. 安装Xf ...
- C. Connect Three(构造)
题目链接:http://codeforces.com/contest/1087/problem/C 题目大意:给你三个点的坐标,让你用尽可能少的方块,让这三个点连起来. 具体思路: 我们先对这三个点进 ...
- OpenCV 用二进制位表示 type & channels 的方式
OpenCV 的类型与通道的表示方法. 参考文件 https://github.com/opencv/opencv/blob/05b15943d6a42c99e5f921b7dbaa8323f3c04 ...
- jQuery 库的优缺点
通用性良好,适合大多数常规网站,省去了为浏览器兼容性写封装函数的麻烦(1+版本支持IE6.7.8,2+版本支持包括IE9在内的现代浏览器). 通用性良好意味着特异性不好,所以jQuery并不适合特异性 ...
- linux中断申请之request_threaded_irq 【转】
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=21977330&id=3755609 在linux里,中断处理分 ...
- 【Linux技术】autotools制作makefile过程详解【转】
转自:http://www.cnblogs.com/lcw/p/3159461.htmlPreface Makefile固然可以帮助make完成它的使命,但要承认的是,编写Makefile确实不是一件 ...
- 制作macOS10.12系列的系统镜像文件
制作macOS10.12系列的系统镜像文件步骤,过程也比较简单,十来个命令.以10.12.6为例,首先,在苹果商店下载系统安装包APP,或者网上下载后把安装APP复制到 应用程序 文件夹. 然后打 ...
- No.19 selenium学习之路之os模块
os模块没有什么好说的,直接看实例就可以了 读取文件内容: open只能读文件的内容,不能读文件夹的内容 常用方法: 1. os.name——判断现在正在实用的平台,Windows 返回 ‘nt'; ...
- CF401D 【Roman and Numbers】
题意将n(n<=10^18)的各位数字重新排列(不允许有前导零) 求 可以构造几个mod m等于0的数字解法状压f[S][k] 表示选用的位数集合为S,mod m 为k的方案数注意不能有前导 ...
- SQL SERVER 断开所有连接(转)
通过sql server management studio对数据进行管理,比如数据库改名等,经常遇到有正在运行的连接,以致无法操作,这时候断掉所有的连接很有必要.代码如下:(会断掉某个库的所有连接, ...
. 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.