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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- BZOJ 1576 [USACO]安全路经Travel (树剖+线段树)
题目大意: 给你一张无向图,求1到其他节点 不经过最短路的最后一条边 的最短路长度,保证每个节点的最短路走法唯一 神题,$USACO$题目的思维是真的好 先$dijkstra$出最短路树 对于每个节点 ...
- BZOJ 1856 [SCOI2010]生成字符串 (组合数)
题目大意:给你n个1和m个0,你要用这些数字组成一个长度为n+m的串,对于任意一个位置k,要保证前k个数字中1的数量大于等于0的数量,求所有合法的串的数量 答案转化为所有方案数-不合法方案数 所有方案 ...
- django-8-django模型系统
<<<表关系实现>>> 1.OneToOne models.OneToOneField('another_table', on_delete=models.CAS ...
- 获取ip,判断用户所在城市
PHP获取IP地址 这个比较简单了,利用PHP自带函数就可以了,PHP中文手册看一下,都有现成的例子,就不过多说明了,直接上代码,A段: <? //PHP获取当前用户IP地址方法 $xp_Use ...
- hdu 4628 Pieces(状态压缩+记忆化搜索)
Pieces Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- 【iOS开发-54】案例学习:通过UIScrollView的缩放图片功能练习代理模式的详细实现
案例:(在模拟器中按住option键,点击鼠标就会出现缩放的手势) (1)在ViewController.m中: --缩放东西是UIScrollView除了滚动之外的还有一个功能,所以须要缩放的东西应 ...
- codeblocks开源的c、c++编译器,小巧方便
1.下载带gun的版本 2.设置编译的位置 3.创建项目 4.执行项目 有意思的开源的c编译器 ~~~
- kibana智能检索发送多次_msearch —— 配置index pattern,同时设置时间段,就知道到底是在哪些索引里去查找数据了
kibanasite/elasticsearch/log-*/_field_stats?level=indices 返回: {"_shards":{"total ...
- 记录一下c++的一点指针所得
c++有两种传值可以改变外部参数,一种是传递指针,另一种是传递引用,对于前者,可以用Ugly(but explicitly),对于后者,Clean(but hidden),在传递的时候有一种值得注意的 ...
- maven关于pom文件配置详解(转载)
转载:http://www.cnblogs.com/hafiz <project xmlns="http://maven.apache.org/POM/4.0.0" xmln ...