zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    KVM安装以及远程连接
    开博客祭
    CQOI 2021
    琐记——学长们
    大事祭
    关于洛谷与博客园的博客的一些声明
    CSP-S 2020 & NOIP 2020 日记与游记
    调和级数
    快速乘
    二叉堆
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11797749.html
Copyright © 2011-2022 走看看