Codeforces Round #259(div2)C(数学期望)
数学题。
关键是求最大值为k时有多少种情况,结果是kn-(k-1)n-1。可以这么想:每一次都从1至k里选,共kn种,这里需要再减去每一次都从1至k-1里面选的情况。当然也可以分类计数法:按出现几次k来分类,然后逆着用一下二项式定理得出结论。
整个的期望是Σk(kn-(k-1)n-1)/mn,其中k=1......n。
这里的技巧在于:由于n<=105, kn显然会RE,那么就先把分母除上,每次算一个小于1的浮点数的n次方,肯定不会RE。C++中乘方用pow函数算是很快的。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
#define INF 1000000000
#define eps 1e-8
#define pii pair<int,int>
#define LL long long int
double m,n,ans=;
int main()
{
//freopen("in3.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%lf%lf",&m,&n);
for(int i=;i<=m;i++)
{
ans+=i*(pow(i/m,n)-pow((i-)/m,n));
}
printf("%.12f\n",ans);
//fclose(stdin);
//fclose(stdout);
return ;
}
Codeforces Round #259(div2)C(数学期望)的更多相关文章
- codeforces Round #259(div2) C解题报告
C. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...
- codeforces Round #259(div2) E解决报告
E. Little Pony and Summer Sun Celebration time limit per test 1 second memory limit per test 256 meg ...
- codeforces Round #259(div2) D解决报告
D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes i ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- 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 #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
随机推荐
- 在英文Windows操作系统上使用SQL Server Management Studio(SSMS)导入Excel 97-2003文件时报错:Failure creating file
今天在公司服务器上使用SQL Server Management Studio(SSMS)导入Excel 97-2003文件(.xls)时报错: Failure creating file. (Mic ...
- [笔记]Go语言在Linux环境下输出彩色字符
Go语言要打印彩色字符与Linux终端输出彩色字符类似,以黑色背景高亮绿色字体为例: fmt.Printf("\n %c[1;40;32m%s%c[0m\n\n", 0x1B, & ...
- idea java web 使用说明
String realPath = request.getSession().getServletContext().getRealPath(uploadPath);//上传压缩包所在目录 ...
- zabbix监控Mariadb数据库
1.介绍: zabbix自带的MySQL插件来监控mysql数据库,但是太过简陋,基本没有啥作用,所以需要做更详细的监控,而percona就有这个详细监控的模版以及脚本,正好拿过来用. percona ...
- mysql 7.5.8 服务无法启动 服务没有报告任何错误
你安装的mysql位置不是c盘的话应该出现此问题. 1.打开bin下的mysql_config.pl文件,查找以下几行,把目录改成你安装mysql的目录即可. my $ldata = 'C:/Prog ...
- 每天一个Linux命令(47)route命令
Linux系统的route命令用于显示和操作内核IP路由表(show / manipulate the IP routing table). (1)用法: 用法: route ...
- Nagios 服务安装
Nagios 环境部署 安装服务包 操作系统:Linux Centos 6.4 32位 安装包:nagios-3.4.3.tar.gz 安装包:nagios-plugins-1.4.13.tar.gz ...
- 主攻ASP.NET.4.5.1 MVC5.0之重生:系统角色与权限(一)
数据结构 权限分配 1.在项目中新建文件夹Helpers 2.在HR.Helpers文件夹下添加EnumMoudle.Cs namespace HR.Helpers { public enum Enu ...
- Python绿色版
Python 安装的时候,有个选项,是问你要安装给所有用户还是只安装给当前用户,你只要选择当前用户,就会把那些需要的 dll ,包括 msvcr90.dll 都给装到 Python 目录下,你只要把 ...
- vRO 7 添加RestHost证书报错
报错类似的错误: Cannot execute request: ; java.security.cert.CertificateException: Certificates does not co ...