牛客多校第五场 F take 期望转化成单独事件概率(模板) 树状数组
链接:https://www.nowcoder.com/acm/contest/143/F
来源:牛客网
Kanade has n boxes , the i-th box has p[i] probability to have an diamond of d[i] size.
At the beginning , Kanade has a diamond of 0 size. She will open the boxes from 1-st to n-th. When she open a box,if there is a diamond in it and it's bigger than the diamond of her , she will replace it with her diamond.
Now you need to calculate the expect number of replacements.
You only need to output the answer module 998244353.
Notice: If x%998244353=y*d %998244353 ,then we denote that x/y%998244353 =d%998244353
输入描述:
The first line has one integer n. Then there are n lines. each line has two integers p[i]*100 and d[i].
输出描述:
Output the answer module 998244353
输入例子:
3
50 1
50 2
50 3
输出例子:
499122178
-->
备注:
1<= n <= 100000 1<=p[i]*100 <=100 1<=d[i]<=10^9 题意:有 n 个箱子,第 i 个箱子有 p[i] 的概率出现大小为 d[i] 的钻石 现在 小A 一开始手里有一个大小为 0 的钻石,他会根据 i 从小到大打开箱子, 如果箱子里有钻石且比小 A 手中的大,那么小 A 就会交换手中的钻石和箱子里 的钻石 求期望的交换次数
分析:求所有交换次数的期望,可以考虑从每次交换的钻石的角度。
要求的期望是每次交换的概率的累加和,而每次交换都是因为遇到更大的钻石(这时才会产生有效的概率)
所以我们要计算的每次交互的期望可以转换成每种钻石被打开的概率,而每种钻石要打开的概率就是其自身打开的概率乘以所有比他大的钻石不打开的概率
这些钻石的概率和就是我们要求的期望
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 10;
const ll mod = 998244353;
struct node {
ll p, w, id;
};
node a[maxn];
ll A[maxn];
bool cmp( node x, node y ) {
if( x.w == y.w ) {
return x.id < y.id;
}
return x.w > y.w;
}
ll qow( ll a, ll b ) {
ll ans = 1;
while(b) {
if( b&1 ) {
ans = ans*a%mod;
}
a = a*a%mod;
b /= 2;
}
return ans;
}
void add( ll x, ll n, ll y ) {
while( x <= n ) {
A[x] = A[x]*y%mod;
x += x&(-x);
}
}
ll ask( ll x ) {
ll ans = 1;
while(x) {
ans = ans*A[x]%mod;
x -= x&(-x);
}
return ans;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll inv = qow(100,mod-2);
ll n;
cin >> n;
for( ll i = 1; i <= n; i ++ ) {
cin >> a[i].p >> a[i].w;
a[i].id = i;
}
sort( a+1, a+n+1, cmp );
for( ll i = 1; i <= n; i ++ ) {
A[i] = 1;
}
ll ans = 0;
for( ll i = 1; i <= n; i ++ ) {
ans += ask(a[i].id-1)*a[i].p%mod*inv%mod;
ans %= mod;
add(a[i].id,n,(100-a[i].p)*inv%mod);
}
cout << ans << endl;
return 0;
}
牛客多校第五场 F take 期望转化成单独事件概率(模板) 树状数组的更多相关文章
- 牛客多校第五场 F take
链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 题目描述 Kanade has n boxes , the i-th box has p[i] ...
- 2019牛客多校第五场 F maximum clique 1 状压dp+最大独立集
maximum clique 1 题意 给出一个集合s,求每个子集的最大独立集的权值和(权值是独立集的点个数) 分析 n比较小,一股浓浓的暴力枚举每一个子集的感觉,但是暴力枚举模拟肯定会T,那么想一想 ...
- 2019牛客多校第五场F maximum clique 1 最大独立集
题意:给你n个数,现在让你选择一个数目最大的集合,使得集合中任意两个数的二进制表示至少有两位不同,问这个集合最大是多大?并且输出具体方案.保证n个数互不相同. 思路:容易发现,如果两个数不能同时在集合 ...
- 牛客多校第三场 F Planting Trees
牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...
- 2019牛客多校第八场 F题 Flowers 计算几何+线段树
2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...
- 【魔改】树状数组 牛客多校第五场I vcd 几何+阅读理解
https://www.nowcoder.com/acm/contest/143/I vc-dimension 题解:分三种情况,组合数学算一下,其中一种要用树状数组维护 技巧(来自UESTC):1. ...
- 牛客多校第四场 F Beautiful Garden
链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...
- 牛客多校第五场 J:Plan
链接:https://www.nowcoder.com/acm/contest/143/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客多校第五场-D-inv
链接:https://www.nowcoder.com/acm/contest/143/D来源:牛客网 题目描述 Kanade has an even number n and a permutati ...
随机推荐
- React Hooks 深入系列 —— 设计模式
本文是 React Hooks 深入系列的后续.此篇详细介绍了 Hooks 相对 class 的优势所在, 并介绍了相关 api 的设计思想, 同时对 Hooks 如何对齐 class 的生命周期钩子 ...
- 又一个轮子--QMapper
1 前言 我喜欢造轮子,一是造的时候就是深刻学习的时候,二是造着造着,说不定某天比世面上的其它轮子都要好呢.比如造过Networksocket,也造过WebApiClient,现在我也要造一个Mapp ...
- POJ18060
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16244 Accepted: 565 ...
- Linux : 性能监测相关命令
[参考文章]:Linux命令大全 [参考文章]:Linux 运行进程实时监控pidstat命令详解 1. 进程级别的监测命令 1.1 top top命令可以实时动态地查看系统的整体运行情况,是一个综 ...
- 通过jmeter发送webservice接口请求
1.webservice接口地址:http://ip:port/...?wsdl 2.接口数据类型:<cuxGmiChukuRmaTrxV><salesrepId xmlns:xsi ...
- 0x15 字符串
KMP算法 next数组的求法 void calc_next() { next[]=; , j=; i<=n; ++i) { &&a[i]!=a[j+]) j=next[j]; ...
- k8s学习笔记
9.deployment:声明式的升级应用 9.1.使用RC实现滚动升级 #kubectl rolling-update kubia-v1 kubia-v2 --image=luksa/kubia:v ...
- 开源音乐下载神器XMusicDownloader更新,支持歌单一键下载,支持无损音乐
开源音乐下载神器XMusicDownloader更新啦,新增网易.腾讯音乐歌单歌曲.歌手歌曲.专辑歌曲一键下载,同时支持下载flac无损音乐. 功能 V1.0 功能开源工具软件XMusicDownlo ...
- [SCOI2009]粉刷匠(动态规划,序列dp,背包)
分别对每块木板做区间dp,设\(g[i][j]\)表示前i个格子,刷恰好j次,并且第i格是合法的最多合法的格子数.从前往后枚举断点来转移就好了. 这样处理再出来\(g[i][j]\)每一块木板i刷j次 ...
- 第 10 篇:小细节 Markdown 文章自动生成目录,提升阅读体验
目录 在文中插入目录 在页面的任何地方插入目录 处理空目录 美化标题的锚点 URL 作者:HelloGitHub-追梦人物 文中涉及的示例代码,已同步更新到 HelloGitHub-Team 仓库 上 ...