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 ...
随机推荐
- 【原】AMFObject数据格式详解
AMF AMF是Action Message Format(动作消息格式)的简写,它是一种二进制的数据格式.它的设计是为了把actionscript里面的数据(包括Object, Array, Boo ...
- java基础(十一)之抽象类和抽象函数
1.抽象函数的语法特征2.抽象类的语法特征3.抽象类的作用 抽象函数 只有函数的定义,没有函数体的函数被称为抽象函数: abstract void func(); 抽象类 使用abstract定义的类 ...
- 记一次if控制器的使用
1.添加if控制器 2.输入判断条件:常见的就是某个变量是不是等于某个值 3.或者用函数助手中的函数 每个版本jmeter函数助手的入口不同,我的直接在菜单上: 选择__jexl3,输入判断条件,点击 ...
- 【想见你】剧情解析byZlc
花两天时间刷完了想见你,精神有点恍惚. 要是刷题也能有这个尽头就好了... 下面给大家带来个人的剧(hu)情(bian)解(luan)析(zao) 穿越条件:一台老式随身听,一首last dance, ...
- 什么是this指针?this的几种指向
在JavaScript中,this指针是在创建时,由系统默认生成的两个隐式参数之一(另一个是arguments). this指针指向与该函数调用进行隐式关联的一个对象,该对象被称为“函数上下文”. t ...
- 每天进步一点点------Altium Designer PCB设计规则中英对照
Electrical(电气规则) Clearance:安全间距规则 Short Circuit:短路规则 UnRouted Net:未布线网络规则 UnConnected Pin:未连线引脚规则 Ro ...
- jmeter实现服务器端后台接口性能测试
实现目的 在进行服务器端后台接口性能测试时,需要连接到Linux服务器端,然后通过命令调用socket接口,这个过程就需要用到jmeter的SSH Command取样器实现了. 脚本实现 设置CSV ...
- shell查找七天之前的文件
#!/bin/bashaweekago=`date -d "7 days ago" +%s`for f in $(ls) do stat -c %Y ${f} aa=`stat - ...
- 远程连接本地mongodb 数据库
绑定本地IP即可 start mongod --dbpath D:\mongodb\data\db --bind_ip 192.168.31.143
- Python字符串排序
看了西红柿的博客,此文纯搬运,方便自己查询用. 原文:https://www.cnblogs.com/tomato0906/articles/4890701.html 1.python中的字符串类型是 ...