传送门

题意

给出m个面的骰子扔n次,取最大值,求期望

分析

暴力算会有重复,而且复杂度不对。

考虑m个面扔n次得到m的概率,发现只要减去(m-1)个面扔n次得到m-1的概率即可,给出example说明

n=2 m=6
6 6 6 6 6 6
5 5 5 5 5 6
4 4 4 4 5 6
3 3 3 4 5 6
2 2 3 4 5 6
1 2 3 4 5 6

得到公式

\[\sum_{i=1}^m{i*(i^n-(i-1)^n)/m^n}
\]

代码

#include <bits/stdc++.h>
using namespace std; #define ll long long
#define ld long double
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}} //Σ{i_1}^m{i^n-(i-1)^n}/{m^n}
int n,m;
long double ans;
long double ex_mod(long double x,int p)
{
long double ret=1;
for(long double tmp=x;p;p>>=1,tmp*=tmp) if(p&1) { ret*=tmp; }
return ret;
}
int main()
{
scanf("%d %d",&m,&n);
F(i,1,m)
{
ans+=i*(ex_mod((ld)i/(ld)m,n)-ex_mod((ld)(i-1)/(ld)m,n));
}
printf("%Lf\n",ans);
return 0;
}

Codeforces Round #259 (Div. 1)A(公式)的更多相关文章

  1. Codeforces Round #259 (Div. 2)

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

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

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

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

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

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

  5. 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 ...

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

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

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

  8. 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 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. Android Notification通知简介

    Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...

  2. Codeforces 920G(二分+容斥)

    题意: 定义F(x,p)表示的是一个数列{y},其中gcd(y,p)=1且y>x 给出x,p,k,求出F(x,p)的第k项 x,p,k<=10^6 分析: 很容易想到先二分,再做差 然后问 ...

  3. Spring mvc之SimpleUrlHandlerMapping

    1.配置文件如下 <bean id="method" class="com.xx.controller.xxxController" scope=&quo ...

  4. 制作自己的网站第二步***在Linux上装上需要的软件以及部署项目配置**

    在购买自己的服务器后,如果想要把项目跑起来,就得安装一些必要的软件. 这里只说一些最基础最基本最不可或缺的几个.其他的可以根据自己的需要 安装使用. 首先,那就是配置jdk了,我们可以通过一些工具把下 ...

  5. ArcGIS engine中Display类库——Display

    转自原文  ArcGIS engine中Display类库——Display Display类库包括了用于显示GIS数据的对象.除了负责实际输出图像的主要显示对象(display object)外,这 ...

  6. 使用MySQL Workbench进行数据库设计——MySQL Workbench用法总结

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/48318877 本文出自[我是干勾鱼的博客] 1 简单介绍 MySQL Workb ...

  7. CSDN-markdown基本的语法说明

    文件夹 概述 简介Markdown CSDN Markdown的功能支持 标题 Setext形式 atx形式 区块引用 分隔线 强调 列表 无序列表 有序列表 注意事项 链接 自己主动链接 普通文本链 ...

  8. ASP.net MVC+ViewData VS ViewBag

         在使用MVC框架的过程中,往界面传值,我们使用的ViewData.如ITOO部分代码图解:      当然除了ViewData,我们还能够使用同卵兄弟(ViewBag)来完毕相同的功能,详情 ...

  9. The sandbox is not sync with the Podfile.lock

    github下载的Demo,很多时候使用到CocoaPods,有的时候因为依赖关系或者版本问题不能编译运行. 出现 以下错误 The sandbox is not sync with the Podf ...

  10. 使用VLC搭建视频直播服务器

    去年我们信息之夜我们进行过视频直播服务,当时我们使用了WMS(Windows Media Server)实现了这个服务,但是编码是微软的WMV,因而像iPhone/Android这样的智能手机无法观看 ...