Skip to main content
  1. Posts/

codeforces 453 A. Little Pony and Expected Maximum

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://codeforces.com/problemset/problem/453/A 题意:m面筛子,每面点数出现的概率相同,连续投掷n次,问出现的最大值的数学期望。 思路:手写样例。。。发现答案为

 。。。记得把(1/m)^n放进去。

观察答案,可以这样理解(我是用样例推出公式后理解。。。数学差的人心好累):如果i为最大值,那么n次每次必须投掷出1..i的点数,概率为 (i/m)^n,但是要至少有一个投掷成i,也就是要减去所有的数都是1..i-1中的情况(概率 为((i-1)/m)^n),

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月02日 星期二 05时17分24秒
 4File Name :code/cf/problem/453A.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E5+7;
34double ans;
35int n ,m;
36double p1[N],p2[N];
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40	freopen("code/in.txt","r",stdin);
41  #endif
42
43	cin>>m>>n;
44	ans =  0;
45	for ( int i = 1 ; i <= m ; i++)
46	{
47	    ans +=i*(pow(i*1.0/m,n*1.0)-pow((i-1)*1.0/m,n*1.0));
48	}
49	printf("%.10f\n",ans);
50
51  #ifndef ONLINE_JUDGE
52  fclose(stdin);
53  #endif
54    return 0;
55}

Related

codeforces 476 B. Dreamoon and WiFi

·2 mins
http://codeforces.com/problemset/problem/476/B 题意:给出两个长度相等-且不超过10的字符串,串1只包含‘-’,’+‘。按照‘+’为1,‘-’为-1累加可以得到一个值。串2还包含若干‘?’,代表该处的值不确定,且为’+‘和’-‘的概率相等,都是0.5.问串2的值和串1相等的概率。 思路:我们可以扫一遍得到‘?’的个数和两个式子的差值。设问号个数为a,差值为b,那么在a个问号中需要有(a-b)/2个为‘+’(容易知道,a,b一定奇偶性相同,所以a-b一定能被2整除),根据超几何分布,概率为 c[a][(a-b)/2]*(1/2)^a; 写的时候可以先打个组合数的表。1A,开心。

codeforces #341 div2 C. Wet Shark and Flowers

·3 mins
http://codeforces.com/contest/621/problem/C C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.

uva 10916 Factstone Benchmark

·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1857 题意:计算最大的n,满足n!/* *********************************************** Author :111qqz Created Time :2016年01月29日 星期五 19时49分25秒 File Name :code/uva/10916.cpp ************************************************ */

uva 107 The Cat in the Hat

·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=43 题意:其实就是给了两个式子。。。(N+1)^h=a,N^h=b,a,b已知,然后求关于N的两个式子.。。 思路:数学上这个方程貌似不可解。。? 所以只能枚举一下==。。。注意精度问题把。。。

uva 846 Steps

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=787 题意:从x增加到y,第一步和最后一步步长只能是1,其他步一定可以是上一步减一,和上一步相等,或者上一步步长加一,三种情况,且步长恒为正。问从x到y最少需要的步数。