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;
}

Educational Codeforces Round 79 (Rated for Div. 2) D. Santa's Bot

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

时间: 2024-07-31 12:12:12

Educational Codeforces Round 79 (Rated for Div. 2) D. Santa's Bot的相关文章

Educational Codeforces Round 79 (Rated for Div. 2)

A. New Year Garland (CF 1279 A) 题目大意 给定红绿蓝三种颜色灯的数量,问能否摆成一排,使得相邻颜色不相同. 解题思路 植树问题.考虑数量最多为\(n\)的颜色的灯俩俩不相邻,那么其他颜色的灯的数量和要大于\(n-1\)即可,大过\(n-1\)的灯直接插到里面就好了. 神奇的代码 #include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>

Educational Codeforces Round 79 (Rated for Div. 2) C. Stack of Presents

链接: https://codeforces.com/contest/1279/problem/C 题意: Santa has to send presents to the kids. He has a large stack of n presents, numbered from 1 to n; the topmost present has number a1, the next present is a2, and so on; the bottom present has numbe

比赛记录[Educational Codeforces Round 79 (Rated for Div. 2)]

首先声明,这是本蒟蒻第一次打CF,也是第一次发博客,大佬勿喷 A                 B                 C              D              E               F 数学      贪心 N/A           N/A             N/A          N/A A. New Year Garland 由于第一次打CF,比赛节奏和心态调整不太好,加上英文题目难以理解(本蒟蒻英语太垃圾),在第一题上水了15分钟. 第

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm