Educational Codeforces Round 79 D Santa's Bot

 

被教育场

题意:先等概率选一个人,再从他想要礼物里等概率选一个,再独立于前两次选择,选一个人,他想要的礼物也被选中,则该组合有效,求组合有效的分数概率(模意义下)

玩一下两个样例应该就能出来知道咋算,虽然我第一个样例是跑了两重循环得出 7/8,拼凑起来才勉强理解的题意。

但知道咋算不一定会code啊。

我就是啊。

模拟了分数的加法乘法运算,通分约分,肯定要WA啊,因为到后面分子分母越来越大存不下。

但实际上,两个分数在某个模数意义下相加可以直接转化,即   x/y+u/v  == x*inv(y) +u*inv(y)

证明我也不会呀

这辈子不可能去证明的

理解还是好理解的

此处由于模数是质数,直接由费马小定理得到逆元来算就行了

 1 #include <bits/stdc++.h>
 2
 3 #ifndef ONLINE_JUDGE
 4 #define debug(x) cout << #x << ": " << x << endl
 5 #else
 6 #define debug(x)
 7 #endif
 8
 9 using namespace std;
10 typedef long long ll;
11 const int MAXN=1e6+7;
12 const int INF=0x3f3f3f3f;
13 const int MOD=998244353;
14
15
16 vector<int>a[MAXN];
17 int cnt[MAXN];
18
19 ll quick(ll x,ll n)  //¿ìËÙÃÝ x^n
20 {
21     ll res=1;
22     while(n)
23     {
24         if(n&1) res=(res*x)%MOD;
25         x=(x*x)%MOD;
26         n>>=1;
27     }
28     return res;
29 }
30
31 ll inv(ll a)
32 {
33     return quick(a,MOD-2);
34 }
35
36 int main()
37 {
38     ios::sync_with_stdio(false);
39     cin.tie(0);
40     int n;
41     cin>>n;
42     for(int i=0;i<n;++i)
43     {
44         int k;
45         cin>>k;
46         while(k--)
47         {
48             int tt;
49             cin>>tt;
50             a[i].push_back(tt);
51             cnt[tt]++;
52         }
53     }
54     ll ans=0;
55     for(int i=0;i<n;++i)
56     {
57         int q=a[i].size();
58         ll tmp=0;
59         for(auto u:a[i])
60             tmp+=cnt[u];
61         ll cur=inv(1ll*n*n%MOD*q%MOD)*tmp%MOD;
62         ans+=cur;
63         debug(ans);
64         debug(tmp);
65         ans%=MOD;
66     }
67     cout<<ans<<endl;
68     return 0;
69 }

Educational Codeforces Round 79 D Santa's Bot

原文地址:https://www.cnblogs.com/Zzqf/p/12111235.html

时间: 2024-10-11 14:33:24

Educational Codeforces Round 79 D Santa's Bot的相关文章

Educational Codeforces Round 79 (Rated for Div. 2) D. Santa&#39;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

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做题记录

这套题感觉出的不咋滴,第四题和第五题难度差了1000分!!! 前四题都还简单,第五题就31人做出……我算了…… 懒得写题解了,做个记录吧(这就是偷懒的理由???) 比赛传送门 A.New Year Garland 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <vector> 6 #define re

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 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l

Educational Codeforces Round 21 F. Card Game(网络流之最大点权独立集)

题目链接:Educational Codeforces Round 21 F. Card Game 题意: 有n个卡片,每个卡片有三个值:p,c,l; 现在让你找一个最小的L,使得满足选出来的卡片l<=L,并且所有卡片的p的和不小于k. 选择卡片时有限制,任意两张卡片的c之和不能为质数. 题解: 和hdu 1565 方格取数(2)一样,都是求最大点权独立集. 不难看出来,这题再多一个二分. 注意的是在构造二部图的时候,按照c值的奇偶性构造. 当c==1时要单独处理,因为如果有多个c==1的卡片,

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