码迷,mamicode.com
首页 > 其他好文 > 详细

The 2019 China Collegiate Programming Contest Harbin Site K. Keeping Rabbits

时间:2019-11-05 13:26:23      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:clu   AMM   i++   put   turn   day   http   expect   tps   

链接:

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

标签:clu   AMM   i++   put   turn   day   http   expect   tps   

原文地址:https://www.cnblogs.com/YDDDD/p/11797749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!