CodeForces 453A
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, them-th face containsm 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 dicen times.
Input
A single line contains two integers m andn (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 exceed10 - 4.
Sample Input
6 1
3.500000000000
6 3
4.958333333333
2 2
1.750000000000
Hint
Consider 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:
题目大意:
求出最大点数的期望(这两个字被平均取代后瞬间没有高尚感- -)。
思路:
若有5个的6面骰子出现最大点为1的次数为1^5,出现最大点为2的的次数为2^5-1^5,以此来推出最大点出现的次数为i^5-(i-1)^5;
求出最大值得期望,由演示样例能够得到 p = ( (1^n-0^n)*1 + (2^n-1^n)*2 。
。
。 +(m^n - (m-1)^n)*m ) / m^n ;将m^n带入
终于得到 p = m - ((m-1)/m)^n + ((m-2)/m)^n。
。。+(1/m)^n ;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<algorithm>
#define LL long long
int a[1010];
using namespace std;
int main()
{
LL s;
int i,j,n,m,k,inr,x;
double sum;
while(scanf("%d%d",&m,&n)!=EOF)
{
sum=0;
for(i=1;i<=m;i++)
{
sum+=i*(pow(i*1.0/m,n)-pow((i-1)*1.0/m,n));<span id="transmark"></span>
}
printf("%.12lf\n",sum);
}
}
CodeForces 453A的更多相关文章
- CodeForces - 453A Little Pony and Expected Maximum
http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...
- CodeForces 453A 概率题
Description Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter ...
- 嘴巴题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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- [读书笔记] R语言实战 (二) 创建数据集
R中的数据结构:标量,向量,数组,数据框,列表 1. 向量:储存数值型,字符型,或者逻辑型数据的一维数组,用c()创建 ** R中没有标量,标量以单元素向量的形式出现 2. 矩阵:二维数组,和向量一 ...
- u-boot启动代码start.S详解
(1)定义入口.由于一个可执行的Image必须有一个入口点,并且只能有一个全局入口,通常这个入口放在ROM(Flash)的0x0地址,因此,必须通知编译器以使其知道这个入口,该工作可通过修改连接器脚本 ...
- 论文阅读笔记“Attention-based Audio-Visual Fusion for Rubust Automatic Speech recognition”
关于论文的阅读笔记 论文的题目是“Attention-based Audio-Visual Fusion for Rubust Automatic Speech recognition”,翻译成中文为 ...
- Git:与eclipse搭配使用
Git:与eclipse搭配使用 1)工程初始化为本地库 工程 ——>右键 ——>Team ——Share Project 在该目录下创建了本地库 这里可以设置用户签名 2)Eclipse ...
- javascript深度克隆函数deepClone
javascript深度克隆函数deepClone function deepClone(obj) { var _toString = Object.prototype.toString; // nu ...
- POJ 1721
好像不需要用到开方什么的... 可以知道,一副牌即是一个循环,那么,由于GCD(L,K)=1,所以一次洗牌后,亦是一个循环.其实,K次洗牌等于是T^(2^K)了.既然是循环,必定有周期.那么,周期是多 ...
- scrapy研究探索(二)——爬w3school.com.cn
下午被一个问题困扰了好一阵.终于使用还有一种方式解决. 開始教程二.关于Scrapy安装.介绍等请移步至教程(一)(http://blog.csdn.net/u012150179/article/de ...
- Hibernate关系映射中的注解
一.@Entity 写在映射表的类上面,表示这是映射来的实体 二.@Id @Column(name = "fid", nullable = false) @Basic @Colum ...
- Java生成验证码_转
为了防止用户恶意,或者使用软件外挂提交一些内容,就得用验证码来阻止,虽然这个会影响用户体验,但为了避免一些问题很多网站都使用了验证码;今天下午参考文档弄了一个验证码,这里分享一下;这是一个web工程, ...
- Another app is currently holding the yum lock; waiting for it to exit…
yum被锁定无法使用,错误信息截图如下:解决方法:rm -rf /var/run/yum.pid 来强行解除锁定,然后你的yum就可以运行了