链接:
https://codeforces.com/gym/102394/problem/K
题意:
DreamGrid is the keeper of n rabbits. Initially, the i-th (1≤i≤n) rabbit has a weight of wi.
Every morning, DreamGrid gives the rabbits a carrot of weight 1 and the rabbits fight for the only carrot. Only one rabbit wins the fight and eats the carrot. After that, the winner‘s weight increases by 1. The whole process of fighting and eating ends before the next morning.
DreamGrid finds that the heavier a rabbit is, the easier it is to win a fight. Formally, if the weights of the rabbits are w′1,w′2,…,w′n before a fight, the probability that the i-th rabbit wins the fight is
w′i∑j=1nw′j
He wants to know the expected weight of every rabbit after k days (k carrots are given and eaten).
思路:
每次选一个,在下一次是总体的概率不变,直接概率乘即可。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;
int Val[MAXN];
int n, k;
int main()
{
ios::sync_with_stdio(false);
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &k);
LL sum = 0;
for (int i = 1;i <= n;i++)
scanf("%d", &Val[i]), sum += Val[i];
for (int i = 1;i <= n;i++)
{
double add = (double)Val[i]/(double)sum;
add = add*k;
printf("%.6lf ", add+Val[i]);
}
puts("");
}
return 0;
}
原文地址:https://www.cnblogs.com/YDDDD/p/11797749.html