Educational Codeforces Round 79 (Rated for Div. 2) - D. Santa's Bot(数论)
题意:有$n$个孩子,第$i$个孩子有$k[i]$件想要的礼物,第$j$个礼物为$a[i][j]$,现在随机挑一个孩子,从他想要的礼物里面随机挑一个,然后送给另一个孩子$($这个孩子可以和第一个孩子是同一个人$)$,问你送的这个礼物在后一个孩子愿望单里的概率。
思路:求出每件礼物出现的次数$cnt[]$,挑出第一个孩子的概率为$\frac{1}{n}$,在他的愿望单里挑出一件礼物的概率为$\frac{1}{k[i]}$,挑出另一个孩子的概率也是$\frac{1}{n}$,挑出的第一个孩子的每件礼物$a[i][j]$出现了$cnt[a[i][j]]$次,那么对于第$i$个孩子的第$j$件礼物$a[i][j]$礼物而言,对答案的贡献就是$\frac{cnt[a[i][j]]}{n^{2}*k[i]}$,所以总概率$$p=\sum_{i=1}^{n}\sum_{j=1}^{k[i]}\frac{cnt[a[i][j]]}{n^{2}*k[i]}$$用快速幂取逆元。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector> using namespace std; typedef long long ll; const int N = ;
const ll mod = ; ll n, k[N], s[N], cnt[N];
vector<ll> v[N]; ll power(ll a, ll n, ll p)
{
ll ba = a, res = ;
while (n) {
if ( == n % ) res = (res * a) % p;
a = (a * a) % p, n /= ;
}
return res;
} int main()
{
scanf("%lld", &n);
for (int i = ; i <= n; i++) {
scanf("%lld", &k[i]);
for (int j = ; j <= k[i]; j++) {
ll a;
scanf("%lld", &a);
cnt[a]++, v[i].push_back(a);
}
}
for (int i = ; i <= n; i++) {
for (int j = ; j < k[i]; j++) s[i] += cnt[v[i][j]];
}
ll res = ;
for (int i = ; i <= n; i++) {
ll tp = ((n * n) % mod * k[i] % mod) % mod;
ll inv = power(tp, mod - , mod);
res = (res + (s[i] * inv) % mod) % mod;
}
printf("%lld\n", res);
return ;
}
Educational Codeforces Round 79 (Rated for Div. 2) - D. Santa's Bot(数论)的更多相关文章
- Educational Codeforces Round 79 (Rated for Div. 2) Finished (A-D)
如果最大值比剩余两个加起来的总和+1还大,就是NO,否则是YES #include<bits/stdc++.h> using namespace std; int main(){ int ...
- CF codeforces A. New Year Garland【Educational Codeforces Round 79 (Rated for Div. 2)】
A. New Year Garland time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 88 (Rated for Div. 2) E. Modular Stability(数论)
题目链接:https://codeforces.com/contest/1359/problem/E 题意 有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数 ...
- Educational Codeforces Round 39 (Rated for Div. 2) B. Weird Subtraction Process[数论/欧几里得算法]
https://zh.wikipedia.org/wiki/%E8%BC%BE%E8%BD%89%E7%9B%B8%E9%99%A4%E6%B3%95 取模也是一样的,就当多减几次. 在欧几里得最初的 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
随机推荐
- 【New】WoSo_我搜 正式上线
[New]WoSo_我搜 正式上线 一站式搜索平台 聚合多种领域搜索引擎,大大提高搜索效率,使搜索更简单 地址:https://huangenet.github.io/WoSo/
- chrome firefox浏览器屏蔽百度热搜
我是原文 操作 点击拦截元素,然后选择页面元素,添加
- dbShape
Usage: dbShape [-help] [-d] [-step <step>] [-output {polygon rect hrect area}] <shapeList&g ...
- 在springboot项目中引入quartz任务调度器。
quartz是一个非常强大的任务调度器.我们可能使用它来管理我们的项目,常见的是做业绩统计等等.当然它的功能远不止这些.我们在这里不介绍quartz的原理,下面讲讲如何在springboot中使用qu ...
- css动画 自动打字,让你的文字飞舞起来
自动打字的效果 非一般的炫酷 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- POJ 3991 括号匹配问题(贪心)
I’m out of stories. For years I’ve been writing stories, some rather silly, just to make simple prob ...
- opencv:形态学操作-开闭操作
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...
- sqli-libs(23-28a关)
Less_23 首先在php文件中加入echo $sql;echo "<br>"; 方法一: :%00 输入?id=1’,报错,说明存在注入漏洞: 输入?id=1' - ...
- 概率dp light1038
题意:问一个数一步步除以他的除数,最后转移到1,所需要的期望步数. 思路,概率dp问题,从结果逆推,本题是从1开始往后推,怎么个推法呢.参考一下别人的博客: 求操作次数的期望时,先设定第i个因子给期望 ...
- 寒假安卓app开发学习记录(2)
今天属实是头疼的一天.开始的时候是简单了解了一下安卓的系统架构,了解到大概分为四个部分. 然后看了两节创建安卓项目的课程,准备去实践一下的时候突然发现我的eclipse里竟然没有Android选项.查 ...