A. Little Pony and Expected Maximum

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/453/problem/A

Description

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 m dots. 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.

Input

A single line contains two integers m and n (1 ≤ m, n ≤ 105).

Output

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.

Sample Input

6 1

Sample Output

3.500000000000

HINT

 

题意

给你一个m面的筛子,然后扔N次,求最大值的期望是多少

题解:

一开始还以为是个概率dp,哎

原来是一道数学题
我们这样想,相当于求一个长度为n的序列,然后问序列中最大值的期望是多少
对于最大值为k的序列,总共有k^n-(k-1)^n这么多个
然后我们递推搞一搞就好啦

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//************************************************************************************** int main()
{
int m,n;
cin>>m>>n;
double pre=;
double ans=;
for(int i=;i<=m;i++)
{
double now=pow((double(i)/double(m)),double(n));
//cout<<now<<endl;
ans+=(now-pre)*i;
pre=now;
}
printf("%.10f\n",ans);
}

Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题的更多相关文章

  1. 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)的是 ...

  2. Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum

    题目链接 题意:一个m个面的骰子,抛掷n次,求这n次里最大值的期望是多少.(看样例就知道) 分析: m个面抛n次的总的情况是m^n, 开始m==1时,只有一种 现在增加m = 2,  则这些情况是新增 ...

  3. Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP

    D. Little Pony and Harmony Chest   Princess Twilight went to Celestia and Luna's old castle to resea ...

  4. Codeforces Round #259 (Div. 2)-D. Little Pony and Harmony Chest

    题目范围给的很小,所以有状压的方向. 我们是构造出一个数列,且数列中每两个数的最大公约数为1; 给的A[I]<=30,这是一个突破点. 可以发现B[I]中的数不会很大,要不然就不满足,所以B[I ...

  5. Codeforces Round #259 (Div. 2)

    A. Little Pony and Crystal Mine 水题,每行D的个数为1,3.......n-2,n,n-2,.....3,1,然后打印即可 #include <iostream& ...

  6. Codeforces Round #259 (Div. 2)AB

    链接:http://codeforces.com/contest/454/problem/A A. Little Pony and Crystal Mine time limit per test 1 ...

  7. Codeforces Round #259 (Div. 2) D

    D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes i ...

  8. Codeforces Round #259 (Div. 1)A(公式)

    传送门 题意 给出m个面的骰子扔n次,取最大值,求期望 分析 暴力算会有重复,而且复杂度不对. 考虑m个面扔n次得到m的概率,发现只要减去(m-1)个面扔n次得到m-1的概率即可,给出example说 ...

  9. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

随机推荐

  1. python 结构化数据解析

    # -*- coding: utf-8 -*- # @Time : 2018/8/31 14:32 # @Author : cxa # @File : glomtest.py # @Software: ...

  2. mybatis待研究

    1. mapper 中_parameter 的含义,是 参数? 为什么?

  3. 利用mysql的binlog恢复数据

    MySQL Binary Log也就是常说的bin-log, ,是mysql执行改动产生的二进制日志文件,其主要作用有两个: * 数据回复 * 主从数据库.用于slave端执行增删改,保持与maste ...

  4. Token机制,防止web页面重复提交

    1.业务要求:页面的数据只能被点击提交一次 2.发生原因: 由于重复点击或者网络重发,或者nginx重发等情况会导致数据被重复提交 3.解决办法: 集群环境:采用token加redis(redis单线 ...

  5. ArcMap2SLD使用

    1.首先打开ArcMap,加载一副mxd地图: 2.打开ArcGIS2SLD,如下图所示: 3.选择样式文件的保存形式,一副mxd地图可能有多个图层,选中In Separate Dateien/In ...

  6. 【小程序开发】购物车加减几件demo

    <!-- 主容器 --> <view class="stepper"> <!-- 减号 --> <text class="{{m ...

  7. SQL-如果指定值存在返回1,如果不存在返回0的SQL语句

    想实现简单的判断一个表中是否有一条记录,可以用这个方式.如以下,table_name是表名,column1是列名. 这条语句会在此条记录存在的时候返回1,不存在时返回0. FROM table_nam ...

  8. 错误/异常:The project cannot be built until build path errors are resolved 和 Unbound classpath container: 'JRE System Library [JavaSE-1.7]' in project 'MyJavaCode';的解决方法

    错误1: The project cannot be built until build path errors are resolved 解决方法: 把java的类库加载进去即可,在工程上右键 选择 ...

  9. DOS命令大全(一)

    #1 一: net use \\ip\ipc$ " " /user:" " 建立IPC空链接 net use \\ip\ipc$ "密码" ...

  10. ZooKeeper的基本概念(二)

    第一篇博文,我们对Zookeeper有了一个简单的认识,而且比较浅显,易懂,这篇博文,我们了解它的基本概念,如下图所示: 了解它的基本概念,有助于我们后面的学习,虽然今天的文章都是概念性质的内容,但是 ...