CodeForces 453A 概率题

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);
    }
}

*/
时间: 2024-10-01 22:11:32

CodeForces 453A 概率题的相关文章

2017-03-16 Codeforces 453A 概率期望,思维 UOJ 228(待补)

Codeforces 453A   A. Little Pony and Expected Maximum 题意:一个m面质地均匀的骰子,每面出现的概率都是独立的1/m, 你需要投掷n次,其结果是这n次出现的最大点数.问投掷n次骰子的结果的期望值是多少,要求相对误差或绝对误差不超过1e-4. tags:枚举骰子出现最大值i,计算出最大值为i时的概率,就得到了答案. 最大值为i的概率=(i/m)^n-((i-1)/m)^n. #include<bits/stdc++.h> using names

Codeforces 453A Little Pony and Expected Maximum 概率题Orz

题目链接:点击打开链接 #include <stdio.h> #include <iostream> #include <algorithm> using namespace std; #define INF 0x3f3f3f3f #define eps 1e-8 #define pi acos(-1.0) typedef long long ll; int main() { int i, j; double m,n; while(cin>>m>>

HDU 4839 The Game of Coins 概率题。(母函数

The Game of Coins mark: #include"cstdio" #include"iostream" #include"queue" #include"algorithm" #include"set" #include"queue" #include"cmath" #include"string.h" #include"

概率题

题目1 (2014腾讯笔试题) 36辆车,6个跑道,最少轮数决出前3名. 分析 分6组,每组跑一次,进行排序. 然后每组第一快的人再跑一遍,确定最快的3组. 最后最快的第一组取3个人,第二快的人取2个人(因为最快的人一定在最快的第一组),第三快的人取1个人.共6个人.再跑一遍. 所以总共是6+1+1=8轮. 以下转自:http://www.acmerblog.com/interviews-about-probability-5359.html 题目2 假设你参加了一个游戏节目,现在要从三个密封的

HDU 4576 Robot(概率题)

Robot Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise. At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the ro

写一个随机洗牌函数——概率题

题目描述: 写一个随机洗牌函数.要求洗出的52!种组合都是等概率的. 也就是你洗出的一种组合的概率是1/(52!).假设已经给你一个完美的随机数发生器. 解题思路: 这是一道概率题 随机洗牌,目的是要做到随机性,要求每一张牌出现的概率要相等. 我们常用的普通扑克牌54张,要做到每张牌出现的概率是1/(54!), 抽第一张牌概率:1/54: 抽第二张牌概率:1/53: 抽第三张牌概率:1/52: -- 一直这样随机地拿下去直到拿完最后1张,我们就从52!种可能中取出了一种排列, 这个排列对应的概率

概率题(一)

转载http://noalgo.info/414.html 概率论是计算机科学非常重要的基础学科之一,概率题也是在程序员求职过程中经常遇到的问题.以下总结若干经典的概率题,作为练习. 1. 在半径为1的圆中随机选取一点. 方法1:在x轴[-1,1],y轴[-1,1]的正方形随机选取一点,如果此点在圆内,则即为所求的点.如果不在圆内,则重新随机直到选到了为止. 方法2:从[0, 2*pi)随机选取一个角度,再在这个方向的半径上随机选取一个点.但半径上的点不能均匀选取,选取的概率要和离圆心的距离成正

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

Codeforces VP/补题小记 1149 C. Tree Generator 给你一棵树的括号序列,每次交换两个括号,维护每次交换之后的直径. ? 考虑括号序列维护树的路径信息和,是将左括号看做 \(-1\) ,右括号看做 \(1\) ,那么一段竖直向上的路径可以表示为括号序列的一个区间和,一段竖直向下的路径可以看做括号序列的一个区间和的相反数.我们要维护的是树的直径,也就是一段连续的和减去紧随其后的一段连续的差.具体来说就是 \[ \max_{\forall [l,r]}\{\sum_{

Codeforces 623D [Amazing概率题]

很有趣的一道题吖! 做法:贪心+迭代 Sigma(i*(pr[i]-pr[i-1])))=n-sigma(pr[i]), 所以我们贪心地是pr[i]尽可能大. 也就是让pr[i]/pr[i-1]尽可能大. 这种类型的贪心,和17EC-Final的那个最小化方差的题挺相似的. #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <cma