zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 79 (Rated for Div. 2) D. Santa's Bot

    链接:

    https://codeforces.com/contest/1279/problem/D

    题意:

    Santa Claus has received letters from n different kids throughout this year. Of course, each kid wants to get some presents from Santa: in particular, the i-th kid asked Santa to give them one of ki different items as a present. Some items could have been asked by multiple kids.

    Santa is really busy, so he wants the New Year Bot to choose the presents for all children. Unfortunately, the Bot's algorithm of choosing presents is bugged. To choose a present for some kid, the Bot does the following:

    choose one kid x equiprobably among all n kids;
    choose some item y equiprobably among all kx items kid x wants;
    choose a kid z who will receive the present equipropably among all n kids (this choice is independent of choosing x and y); the resulting triple (x,y,z) is called the decision of the Bot.
    If kid z listed item y as an item they want to receive, then the decision valid. Otherwise, the Bot's choice is invalid.

    Santa is aware of the bug, but he can't estimate if this bug is really severe. To do so, he wants to know the probability that one decision generated according to the aforementioned algorithm is valid. Can you help him?
    就是先选一个人,再从这个人的k个礼物选一个,再重选一个人,可以与第一个重复,如果这个人想要的礼物中有之前选的礼物,就是一个好的选择。
    计算出现好的选择的概率。

    思路:

    算出取出每个值的概率,再遍历每个人,这个人的每个值被取出的概率乘上选择这个人的概率再累加一下

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MOD = 998244353;
    const int MAXN = 1e6+10;
    
    int P[MAXN];
    int n;
    vector<int> vec[MAXN];
    
    LL PowMod(LL a, LL b, LL p)
    {
        LL res = 1;
        while(b)
        {
            if (b&1)
                res = res*a%p;
            a = a*a%p;
            b >>= 1;
        }
        return res;
    }
    
    LL GetP(LL x, LL y)
    {
        return x*PowMod(y, MOD-2, MOD)%MOD;
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
        cin >> n;
        int k, val;
        for (int i = 1;i <= n;i++)
        {
            cin >> k;
            for (int j = 1;j <= k;j++)
            {
                cin >> val;
                vec[i].push_back(val);
            }
        }
        LL pone = GetP(1, n);
        for (int i = 1;i <= n;i++)
        {
            int sum = vec[i].size();
            for (auto v: vec[i])
                P[v] = (P[v]+pone*GetP(1, sum)%MOD)%MOD;
        }
        LL ans = 0;
        for (int i = 1;i <= n;i++)
        {
            for (auto v: vec[i])
                ans = (ans + pone*P[v]%MOD)%MOD;
        }
        cout << ans << endl;
    
        return 0;
    }
    
  • 相关阅读:
    weibo4j中的 jar解释
    Android使用系统Intent实现分享功能及将应用加入分享列表++分享邮箱实现
    Android ListView 技巧 (一) Android ListView Header
    [Android]使用AChartEngine画柱状图 .
    【TCPIP】握手挥手详解
    python : import this. 如此幽默,让人不得不爱
    Forbidden (403) CSRF verification failed. Request aborted.
    Django修改model如何同步数据库
    程序员的7种武器【转】
    Django Admin 录入中文错误解决办法
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12113515.html
Copyright © 2011-2022 走看看