Codeforces Round #259 (Div. 1)A(公式)
传送门
题意
给出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
得到公式
\]
代码
#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(公式)的更多相关文章
- Codeforces Round #259 (Div. 2)
A. Little Pony and Crystal Mine 水题,每行D的个数为1,3.......n-2,n,n-2,.....3,1,然后打印即可 #include <iostream& ...
- Codeforces Round #259 (Div. 2)AB
链接:http://codeforces.com/contest/454/problem/A A. Little Pony and Crystal Mine time limit per test 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)的是 ...
- Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum
题目链接 题意:一个m个面的骰子,抛掷n次,求这n次里最大值的期望是多少.(看样例就知道) 分析: m个面抛n次的总的情况是m^n, 开始m==1时,只有一种 现在增加m = 2, 则这些情况是新增 ...
- 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 ...
- Codeforces Round #259 (Div. 2)-D. Little Pony and Harmony Chest
题目范围给的很小,所以有状压的方向. 我们是构造出一个数列,且数列中每两个数的最大公约数为1; 给的A[I]<=30,这是一个突破点. 可以发现B[I]中的数不会很大,要不然就不满足,所以B[I ...
- 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 ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- C++,C程序设计入门——《高质量程序设计第4章》
1. 连接规范 1. extern “C” 2. 一部分采用C的连接规范 #ifdef __cplusplus extern "C" { #endif #ifdef __cplus ...
- python学习之-- redis模块管道/订阅发布
redis 模块操作剩余其他常用操作 delete(*names):删除任意的数据类型exists(name):检测redis的name是否存在keys(pattern='*'):根据模型获取redi ...
- linux otl oracle数据库连接例子
#include <string> #include <iostream> using namespace std; #define OTL_ORA10G //我连的是LI ...
- maven pom.xml文件介绍
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 【TFS 2017 CI/CD系列 - 03】-- Release篇
为Project创建Release必须要先创建Build,若还没有Build definition请看上一篇文章:[TFS 2017 CI/CD系列 - 02]-- Build篇 一.创建Releas ...
- send-mail: fatal: parameter inet_interfaces: no local interface found for ::1
转载:http://blog.csdn.net/csdnones/article/details/50717934 发送邮件: [root@iZ23whn33jnZ log]# echo '这是邮件标 ...
- kvm虚拟化学习笔记(二)之linux kvm虚拟机安装
KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...
- Centos 6.x 安装Nagios及WEB管理nagiosql实现windows及linux监控指南
一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报 ...
- VB6 如何自定义代码字体和支持鼠标滚轮
1 点击工具-选项-编辑器格式,把代码改成需要的字体和大小.(一般微软雅黑,16号字体比较好) 2 从以下网站下载VB6增强工具,可以支持鼠标滚轮代替右侧滚动条查看代码,按F3还可以切换代码窗口和 ...
- Visual Studio VS如何重置所有设置
工具-导入和导出设置-重置所有设置,点击下一步即可.