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
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:
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 概率题的更多相关文章
- Codeforces VP/补题小记 (持续填坑)
Codeforces VP/补题小记 1149 C. Tree Generator 给你一棵树的括号序列,每次交换两个括号,维护每次交换之后的直径. 考虑括号序列维护树的路径信息和,是将左括号看做 ...
- Codeforces 623D [Amazing概率题]
很有趣的一道题吖! 做法:贪心+迭代 Sigma(i*(pr[i]-pr[i-1])))=n-sigma(pr[i]), 所以我们贪心地是pr[i]尽可能大. 也就是让pr[i]/pr[i-1]尽可能 ...
- 嘴巴题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 ...
- CodeForces - 453A Little Pony and Expected Maximum
http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- HDU 5245 Joyful(概率题求期望)
D - Joyful Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- 我要好offer之 概率题大总结
1. 利用等概率Rand5生成等概率Rand3 Rand5生成等概率Rand3 这个题目可以扩展为:利用等概率RandM生成等概率RandN (M > N) 这里,我们首先明白一个简单的知识点: ...
随机推荐
- (Go)07.Go语言中strings和strconv包示例代码详解02
1.strings使用 统计字符串出现次数 strings.Count(s string, substr string) int Count 用于计算字符串 substr 在字符串 s 中出现的非重叠 ...
- PCB MS SQL 将字符串分割,并指定索引返回字符串(标量函数)
Create FUNCTION [dbo].[SplitIndex] ( @str AS VARCHAR(max), @Index AS INT, ) = '/' ) ) AS BEGIN ) --待 ...
- Django day02
一:Django 中 app 的概念 每个项目里面都会 有很多不同的模块,我们可以把它们写在一个项目里,我们把模块分成一个一个不同的app,这样写可以便于管理,写的一些项目也可能不单单是一个页面,还可 ...
- S - New Year Transportation
Problem description New Year is coming in Line World! In this world, there are n cells numbered by i ...
- Mysql 时间、字符串、时间戳互转
时间转字符串 select date_format(now(),'%Y-%m-%d'); 时间转时间戳 select UNIX_TIMESTAMP(now()); 时间戳转时间 ) :: 时间戳转字符 ...
- Spring Boot (13) druid监控
druid druid是和tomcat jdbc一样优秀的连接池,出自阿里巴巴.除了连接池,druid哈hi有一个很实用的监控功能. pom.xml 添加了以下依赖后,会自动用druid连接池替代默认 ...
- Spring Boot (8) 全局异常处理
服务层和dao层的最终异常会交给controller处理,控制层的异常则会记录日志系统. 新建一个类用来处理异常,名字随便GlobalDefaultExceptionHandler.java,加上@C ...
- THREE.js代码备份——webgl - materials - cube refraction [balls](以上下左右前后6张图片构成立体场景、透明球体效果)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - ma ...
- 使用脚本卸载.net framework for mac
官方只提供了安装包,没提供卸载
- uni-app判断各大平台的语法
uni-app是一款强大的前端框架,它除了pc端其他都可以实现,打包原生app.手机h5页面,微信小程序, 但是有一个问题就是本生的app和微信小程序是有一定的区别的,因为app有标题栏,返回键,而微 ...