【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 ...
随机推荐
- python调用百度语音识别接口实时识别
1.本文直接上干货 奉献代码:https://github.com/wuzaipei/audio_discern/tree/master/%E8%AF%AD%E9%9F%B3%E8%AF%86%E5% ...
- 信息安全学习笔记--XSS
一.XSS简介 XSS (Cross Site Scripting)是一种经常出现在web应用中的计算机安全漏洞,它允许恶意web用户将代码植入到提供给其它用户使用的页面中.比如这些代码包括HTML代 ...
- [转]激活函数ReLU、Leaky ReLU、PReLU和RReLU
“激活函数”能分成两类——“饱和激活函数”和“非饱和激活函数”. sigmoid和tanh是“饱和激活函数”,而ReLU及其变体则是“非饱和激活函数”.使用“非饱和激活函数”的优势在于两点: 1 ...
- 基于Netty4.1.29.Final的helloworld实现.使用idea
服务端: //服务端 public class Server { public static void main(String[] args) { //创建两个线程组 EventLoopGroup c ...
- FPGA quartus开发中常见的错误处理
1.Warning: An incorrect timescale is selected for the Verilog Output (.VO) file of this PLL design. ...
- HDU 6214 Smallest Minimum Cut 最小割,权值编码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...
- Django Xadmin - 重构django admin
一.Django admin的执行流程 https://www.cnblogs.com/weihengblog/p/9122509.html 我的博客,介绍了django admin执行流程 二.Xa ...
- Android性能测试工具之APT
1.APT工具简介: APT是一个eclipse插件,可以实时监控Android手机上多个应用的CPU.内存数据曲线,并保存数据:另外还支持自动获取内存快照.PMAP文件分析等,方便开发人员自测或者测 ...
- PlantUML——4.实例演示1
给自己发消息 @startuml Alice -> Alice : This is a signal to self.\nIt also demonstrates \nmultiline tex ...
- 读书笔记--C陷阱与缺陷(七)
第七章 1.null指针并不指向任何对象,所以只用于赋值和比较运算,其他使用目的都是非法的. 误用null指针的后果是未定义的,根据编译器各异. 有的编译器对内存位置0只读,有的可读写. 书中给出了一 ...