Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum

题目链接

题意:

分析:

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cmath>
 5 #include <cstdio>
 6 #include <vector>
 7 #include <algorithm>
 8 #define LL long long
 9 using namespace std;
10
11 int main()
12 {
13     int i;
14     double ans, n, m, temp, pre;
15     while(cin>>m>>n)
16     {
17         ans = pow(1.0/m, n);
18         pre = ans;
19         for(i = 2; i <= m; i++)
20         {
21             temp = pow(i/m, n);
22             ans += (temp-pre)*i;
23             pre = temp;
24         }
25
26         printf("%.4lf\n", ans);
27     }
28     return 0;
29 }

Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum

时间: 2024-10-13 14:06:02

Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum的相关文章

Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)

题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是所有最大值是xi的情况数/总情况数一共是m^n种,掷n次,所有最大值是xi的情况数应该是xi^n,但是这里边却包含着最大值非xi且不超过xi的种数,所以再减去最大值是xi-1或者最大值不超过这个的情况数.即sum += xi * (xi^n-(xi-1)^n)/m^n,但是这样求肯定是不行,因为m

Codeforces Round #259 (Div. 2)-D. Little Pony and Harmony Chest

题目范围给的很小,所以有状压的方向. 我们是构造出一个数列,且数列中每两个数的最大公约数为1; 给的A[I]<=30,这是一个突破点. 可以发现B[I]中的数不会很大,要不然就不满足,所以B[I]<=60左右.构造DP方程DP[I][J]=MIN(DP[I][J],DP[I][J^C[K]]+abs(a[i]-k)); K为我们假设把这个数填进数组中的数.同时开相同空间记录位置,方便输出结果.. #include<iostream> #include<stdio.h>

Codeforces Round #259 (Div. 2) B. Little Pony and Sort by Shift(模拟)

题目链接:Codeforces Round #259 (Div. 2)  B. Little Pony and Sort by Shift 求给出的序列最少移动多少次成为非下降序列.移动方式:只能将最后一个元素移到第一个位置 即:a1,?a2,?...,?an?→?an,?a1,?a2,?...,?an?-?1. 从后前开始搜非下降的子序列,然后前面的子序列接在其后面,最后判断变化后的序列是否是非下降序列即可. AC代码: #include<stdio.h> #include<strin

Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP

D. Little Pony and Harmony Chest Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. A sequence of positive integers bi is harmony if and only if for every two elements of the sequence their gr

Codeforces Round #259 (Div. 1)——Little Pony and Expected Maximum

题目连接 题意: 输入n.m,表示一个n面的色子(面上的值为1-n),投掷m次,求得到的最大值的期望(1?≤?m,?n?≤?105). 分析: 假设当前得到的最大值是Max,那么对应的概率是:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ),(1 <= k <= n):化简就可以得到:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ) - ((Max - 1

Codeforces Round #259 (Div. 1)——Little Pony and Harmony Chest

题目连接 题意: 给n个整数ai,求一个序列bi,使得b序列中任意两个数互质,而且sigma(abs(ai - bi))最小,输出任意一个b序列即可 (1?≤?n?≤?100)  (1?≤?ai?≤?30) 分析: 首先明确一点,题目没有限制b的范围....为此wa了好多次,不过可以推断出来,b肯定小于等于60 任意两个数互质,也就是说,对于新加入的一个bi,如果知道了之前所有数的质因子,那么当前数只要没有这个质因子就是一种满足的情况.而60以内的质数不到20个,所以直接状压DP即可.DP[i]

Codeforces Round #259 (Div. 2) (简单模拟实现题)

题目链接:http://codeforces.com/problemset/problem/454/A A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine

Codeforces Round #259 (Div. 2) (序列)

题目链接:http://codeforces.com/contest/454/problem/B B. Little Pony and Sort by Shift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day, Twilight Sparkle is interested in how to sort a se

Codeforces Round #259 (Div. 2)

A. Little Pony and Crystal Mine 题意:输出一个类似于十字形的东西 题解:直接打印即可... 代码: 1 var n,i,j:longint; 2 begin 3 readln(n); 4 for i:=1 to n>>1 do 5 begin 6 for j:=1 to (n-i<<1+1)>>1 do write('*'); 7 for j:=1 to i<<1-1 do write('D'); 8 for j:=1 to