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

Input
6 1
Output
3.500000000000
Input
6 3
Output
4.958333333333
Input
2 2
Output
1.750000000000

Hint

Consider the third test example. If you've made two tosses:

  1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
  2. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
  3. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
  4. 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:

You can read about expectation using the following link:
http://en.wikipedia.org/wiki/Expected_value


#include<iostream> //此题要先转化成概率形式,否则会爆double的
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
#define INF 0x3f3f3f3f using namespace std; int a[200010];
int main()
{
int n, m;
while(~scanf("%d%d", &m, &n))
{
double ans = 0;
for (int i = 1; i < m; i++)
ans += pow((double)i / m, n);
printf("%.12lf\n", (double) m - ans);
}
}
/*
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
#define INF 0x3f3f3f3f using namespace std; int a[200010];
int main()
{
int n,m;
while(~scanf("%d%d",&m,&n))
{
double sum1=0,sum2=0,sum=0;
for(int i=1;i<=m;i++)
{
sum2=pow(i*1.0/m,n);
sum+=i*(sum2-sum1);
sum1=sum2;
}
double ss=1.0*sum;
printf("%.12lf\n",ss);
}
} */

CodeForces 453A 概率题的更多相关文章

  1. Codeforces VP/补题小记 (持续填坑)

    Codeforces VP/补题小记 1149 C. Tree Generator 给你一棵树的括号序列,每次交换两个括号,维护每次交换之后的直径. ​ 考虑括号序列维护树的路径信息和,是将左括号看做 ...

  2. Codeforces 623D [Amazing概率题]

    很有趣的一道题吖! 做法:贪心+迭代 Sigma(i*(pr[i]-pr[i-1])))=n-sigma(pr[i]), 所以我们贪心地是pr[i]尽可能大. 也就是让pr[i]/pr[i-1]尽可能 ...

  3. 嘴巴题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 ...

  4. CodeForces - 453A Little Pony and Expected Maximum

    http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...

  5. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  6. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  7. codeforces #261 C题 Pashmak and Buses(瞎搞)

    题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...

  8. HDU 5245 Joyful(概率题求期望)

    D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  9. 我要好offer之 概率题大总结

    1. 利用等概率Rand5生成等概率Rand3 Rand5生成等概率Rand3 这个题目可以扩展为:利用等概率RandM生成等概率RandN (M > N) 这里,我们首先明白一个简单的知识点: ...

随机推荐

  1. Zeppelin0.6.2+sparkR2.0.2环境搭建

    0.序 先吐槽一下网上旧版本的Zeppelin和R的安装,让我折腾了几个小时. 不过最终还是调通了也不容易,其实我现在一点R都没有学呢,只是刚看了一节课,但是这个工具既然出现在了Spark中,我想它还 ...

  2. [转]Java web 开发 获取用户ip

    如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,那么真正的用户端的真实IP则是取X-Forwarded-For中第一个非unknown的有效IP字符串. pu ...

  3. css3中的box-sizing属性的使用

    box-sizing属性用来定义元素的width和height所表示的区域,该属性一般有三种值:content-box.border-box.inherit. 其中inherit表示box-sizin ...

  4. java中equals方法和==的用法

    java中equals方法的用法以及==的用法(参考一)equals 方法是 java.lang.Object 类的方法.两种用法说明:(1对于字符串变量来说,使用“==”和“equals()”方法比 ...

  5. Java中final、finally、finalize的区别与用法

    1.简单区别:final用于声明属性,方法和类,分别表示属性不可交变,方法不可覆盖,类不可继承.finally是异常处理语句结构的一部分,表示总是执行.finalize是Object类的一个方法,在垃 ...

  6. Android几种常见的多渠道(批量)打包方式介绍

    多渠道打包,主要是为了统计不同的渠道上包的下载数量,渠道越多,我们需要打的包数量越多,这个时候,我们没法去使用单纯的手动打包去一个一个的生成不同的渠道包,我们需要更高效的打包方式. 声明渠道方式一: ...

  7. akka框架——异步非阻塞高并发处理框架

    akka actor, akka cluster akka是一系列框架,包括akka-actor, akka-remote, akka-cluster, akka-stream等,分别具有高并发处理模 ...

  8. ★Java语法(五)——————————三元运算符

    package 课上练习; public class 三元运算符 { //用法: 数据类型 变量 = 布尔表达式? 条件满足设置内容:条件不满足设置内容 : public static void ma ...

  9. 打包Python程序

    我选择的是pyinstaller,(py2exe到目前为止只支持到Python3.4). 安装.如果能联网最后用pip.在cmd中输入pip install Pyinstaller.如果不能联网,可以 ...

  10. 【JSP】中文乱码问题

     原作者http://www.cnblogs.com/xing901022/p/4354529.html 阅读目录 之前总是碰到JSP页面乱码的问题,每次都是现在网上搜,然后胡乱改,改完也不明白原因. ...