牛客多校第五场 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 ...
随机推荐
- 雪花算法【分布式ID问题】【刘新宇】
分布式ID 1 方案选择 UUID UUID是通用唯一识别码(Universally Unique Identifier)的缩写,开放软件基金会(OSF)规范定义了包括网卡MAC地址.时间戳.名字空间 ...
- 刷脸即可解锁让iDevice取证不再难如登天
最近有则取证相关的消息,链接如下,光看标题便知道与Apple的Face ID有关. https://www.cnet.com/news/fbi-unlocked-an-iphone-x-by-forc ...
- MOCTF-WEB-writeup
MOCTF-WEB-writeup 好菜,除了简单的几个题,自己会做,难的都是看老大WP完成的,太菜了 啥姿势都不会,就此记录一下,供日后查看及反省.菜鸡的自我修养 0x01 一道水题 题目链接:ht ...
- cookie池的维护
存储形式: 存储在redis中,“spider_name:username–password":cookie 建立py文件及包含方法: initcookies() 初始化所有账号的cooki ...
- Docker——理解好镜像和容器的关系
关注公众号,大家可以在公众号后台回复“博客园”,免费获得作者 Java 知识体系/面试必看资料. 镜像也是 docker 的核心组件之一,镜像时容器运行的基础,容器是镜像运行后的形态.前面我们介绍了 ...
- 数据结构之堆栈java版
import java.lang.reflect.Array; /* 具体原理在c++版已经说的很清楚,这里不再赘述, 就提一点:java的泛型具有边界效应,一旦离开作用域立马被替换为object类型 ...
- 利用DoHome APP和音箱控制LED灯实验参考步骤
准备材料: Arduino Uno 一块 Arduino 扩展板 购买链接 DT-06模块一个 购买链接 安卓手机一个 小度音箱一个 小灯珠一个 杜邦线若干 1.DT-06固 ...
- Kafka单线程Consumer及参数详解
请使用0.9以后的版本: 示例代码 Properties props = new Properties(); props.put("bootstrap.servers", &quo ...
- SpringDataJpa在一对多、多对多关系映射时出现StackOverflowError
在使用spring-data-jpa时,进行一对多配置后,在调用save方法时,出现内存溢出. 产生原因一:为了方便看信息,在两类中分别重写了 toString 方法,导致查询加载时两类在互相调用对方 ...
- IDEA部署 java Web项目 常见配置
前言 从eclipse上转到idea上,第一次使用idea部署web项目,真折磨人,写了一个 helloworld 5分钟,了解idea部署web项目5小时. 我使用的是idea 2019.1版本,其 ...