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. php获得本机ipv4地址

    if (isset($_ENV["HOSTNAME"])) $MachineName = $_ENV["HOSTNAME"]; else if (isset($ ...

  2. centos7安装python3.7和ipython

    一.centos7为刚安装的 1)配置yum源和epel源 采用国内源 查看yum的配置文件 (里面的镜像网址)是否ping的通 全部更改成 国内的 yum .epel源 在图中位置 下载相应的 re ...

  3. HBase的集群搭建(1、3、5节点都适用)

    见 5 hbase-shell + hbase的java api

  4. Dotnet Core2.1 使用CodeFirst

    一.添加Mysql引用 二.添加连接字符串 三.配置startup.cs 三.初始化数据库 Add-Migration init Update-Database 四.数据迁移 user实体添加了pas ...

  5. 一张图说明DIV盒子距离

    虚线的宽高为你实际指定的width和height 虚线外的白色区域为padding 红色区域为border的width 红色外的区域为margin

  6. selenium选错弹出层的下拉框

    要先选中这个弹出层的form元素,再找下拉框 public void downSelectBox(){ driver.get("https://www.imooc.com/user/setp ...

  7. PHP执行Mysql数据库的备份和还原

    使用mysqldump命令备份 mysqldump命令将数据库中的数据备份成一个文本文件.表的结构和表中的数据将存储在生成的文本文件中. mysqldump命令的工作原理很简单.它先查出需要备份的表的 ...

  8. 使用Visio—UML画类图

    在一个VS工程中,由于类的个数较多,而参数描述不是特别清晰.若此工程的生命周期较长,则有必要对工程进行完整分析,给出完整的文档.需要画出类图,并对每个成员进行详细描述. 一.画出类图 在VIsio中, ...

  9. (转)基于MVC4+EasyUI的Web开发框架经验总结(12)--利用Jquery处理数据交互的几种方式

    http://www.cnblogs.com/wuhuacong/p/4085682.html 在基于MVC4+EasyUI的Web开发框架里面,大量采用了Jquery的方法,对数据进行请求或者提交, ...

  10. python tips:最内嵌套作用域规则,闭包与装饰器

    在作用域与名字空间提到,python是静态作用域,变量定义的位置决定了变量作用的范围.变量沿着local,global,builtins的路径搜索,直觉上就是从里到外搜索变量,这称为最内嵌套作用域规则 ...