The 2019 China Collegiate Programming Contest Harbin Site K. Keeping Rabbits
Posted ydddd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The 2019 China Collegiate Programming Contest Harbin Site K. Keeping Rabbits相关的知识,希望对你有一定的参考价值。
链接:
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;
}
以上是关于The 2019 China Collegiate Programming Contest Harbin Site K. Keeping Rabbits的主要内容,如果未能解决你的问题,请参考以下文章
The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners
The 2019 China Collegiate Programming Contest Harbin Site I. Interesting Permutation
The 2019 China Collegiate Programming Contest Harbin Site K. Keeping Rabbits
The 2019 China Collegiate Programming Contest Harbin Site I - Interesting Permutation 思维
The 2019 China Collegiate Programming Contest Harbin Site A - Artful Paintings 差分约束
Rolling The Polygon (2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest)(The