2510: 弱题

来源:互联网 发布:龙bt发布永久域名 编辑:程序博客网 时间:2024/05/22 12:37

2510: 弱题

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 321  Solved: 166
[Submit][Status][Discuss]

Description

M个球,一开始每个球均有一个初始标号,标号范围为1~N且为整数,标号为i的球有ai个,并保证Σai = M
每次操作等概率取出一个球(即取出每个球的概率均为1/M),若这个球标号为kk < N),则将它重新标号为k + 1;若这个球标号为N,则将其重标号为1。(取出球后并不将其丢弃)
现在你需要求出,经过K次这样的操作后,每个标号的球的期望个数。
 

Input

第1行包含三个正整数NMK,表示了标号与球的个数以及操作次数。
第2行包含N非负整数ai,表示初始标号为i的球有ai个。
 

Output

应包含N行,第i行为标号为i的球的期望个数,四舍五入保留3位小数。
 

Sample Input

2 3 2
3 0

Sample Output

1.667
1.333

HINT

【样例说明】

第1次操作后,由于标号为2球个数为0,所以必然是一个标号为1的球变为标号为2的球。所以有2个标号为1的球,有1个标号为2的球。

第2次操作后,有1/3的概率标号为2的球变为标号为1的球(此时标号为1的球有3个),有2/3的概率标号为1的球变为标号为2的球(此时标号为1的球有1个),所以标号为1的球的期望个数为1/3*3+2/3*1 = 5/3。同理可求出标号为2的球期望个数为4/3。

 

【数据规模与约定】

对于10%的数据,N ≤ 5, M ≤ 5, K ≤ 10;

对于20%的数据,N ≤ 20, M ≤ 50, K ≤ 20;

对于30%的数据,N ≤ 100, M ≤ 100, K ≤ 100;

对于40%的数据,M ≤ 1000, K ≤ 1000;

对于100%的数据,N ≤ 1000, M ≤ 100,000,000, K ≤ 2,147,483,647。




Source

2011福建集训

[Submit][Status][Discuss]



#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#include<stack>#include<bitset>#include<ext/pb_ds/priority_queue.hpp>using namespace std;typedef double DB;const int N = 1000;DB m,f[N],A[N],B[N],C[N],D[N];int n,k;int pre(const int &x) {return !x ? n - 1 : x - 1;}int nex(const int &x) {return x == n - 1 ? 0 : x + 1;}void Mul(DB *r,DB *c,int typ){int pos = 0;for (int i = 0; i < n; i++,pos = pre(pos)){int now = pos; D[i] = 0;for (int j = 0; j < n; j++,now = nex(now))D[i] += r[j] * c[now];}if (typ == 1){for (int i = 0; i < n; i++) C[i] = D[i];}else{for (int i = 0; i < n; i++) A[i] = D[i],B[i] = D[(n - i) % n];}}void ksm(int y){for (; y; y >>= 1){if (y & 1) Mul(C,B,1);Mul(A,B,2);}}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n >> m >> k;if (n == 1) {cout << m; return 0;}for (int i = 0; i < n; i++) scanf("%lf",&f[i]);DB X = (m - 1.00) / m,Y = 1.00 / m; C[0] = 1.00;A[0] = B[0] = X; A[1] = B[n - 1] = Y; ksm(k);for (int i = 0; i < n; i++){DB Ans = 0.00;for (int j = 0; j < n; j++)Ans += f[j] * C[(i - j + n) % n];printf("%.3f\n",Ans);}return 0;}


0 0
原创粉丝点击