链接: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

输入

复制

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 期望转化成单独事件概率(模板) 树状数组的更多相关文章

  1. 牛客多校第五场 F take

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 题目描述 Kanade has n boxes , the i-th box has p[i] ...

  2. 2019牛客多校第五场 F maximum clique 1 状压dp+最大独立集

    maximum clique 1 题意 给出一个集合s,求每个子集的最大独立集的权值和(权值是独立集的点个数) 分析 n比较小,一股浓浓的暴力枚举每一个子集的感觉,但是暴力枚举模拟肯定会T,那么想一想 ...

  3. 2019牛客多校第五场F maximum clique 1 最大独立集

    题意:给你n个数,现在让你选择一个数目最大的集合,使得集合中任意两个数的二进制表示至少有两位不同,问这个集合最大是多大?并且输出具体方案.保证n个数互不相同. 思路:容易发现,如果两个数不能同时在集合 ...

  4. 牛客多校第三场 F Planting Trees

    牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...

  5. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  6. 【魔改】树状数组 牛客多校第五场I vcd 几何+阅读理解

    https://www.nowcoder.com/acm/contest/143/I vc-dimension 题解:分三种情况,组合数学算一下,其中一种要用树状数组维护 技巧(来自UESTC):1. ...

  7. 牛客多校第四场 F Beautiful Garden

    链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...

  8. 牛客多校第五场 J:Plan

    链接:https://www.nowcoder.com/acm/contest/143/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  9. 牛客多校第五场-D-inv

    链接:https://www.nowcoder.com/acm/contest/143/D来源:牛客网 题目描述 Kanade has an even number n and a permutati ...

随机推荐

  1. js获得页面get跳转的参数

    通过js获得页面跳转参数 页面通过window.location.href或通过window.parent.location.href进行页面跳转,在新的页面如何获得相应的参数呢? window.lo ...

  2. 【有容云】PPT | 容器与CICD的遇见

    编者注:本文为12月21日晚上8点有容云高级咨询顾问蒋运龙在腾讯课堂中演讲的PPT,本次课堂为有容云主办的线上直播Docker Live时代●Online Meetup-第四期:容器与CICD的遇见, ...

  3. Wpf窗口设置可拖动

    在窗口界面的一个控件(TopGrid)设置如下MouseLeftButtonDown事件即可 private void TopGrid_MouseLeftButtonDown(object sende ...

  4. Pandas随机采样

    实现对DataFrame对象随机采样 pandas是基于numpy建立起来的,所以numpy大部分函数可作用于DataFrame和Series数据结构. numpy.random.permutatio ...

  5. Java统计代码行数

    package test; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im ...

  6. JWT详解

    目录 1.前言 2.JWT的数据结构 2.1 Header 2.2 Payload 2.3 Signature 2.4 Base64URL 3. JWT的实现   1.前言 定义:JSON Web T ...

  7. 修改 jupyter notebook的默认文件夹位置

    安装好Anaconda 3以后,就可以使用Jupyter notebook了,但是我们打开Jupyter notebook后,发现界面是一个默认的目录,这个目录在哪里?如果想把自己写的程序文件保存在自 ...

  8. ORACLE中添加删除主键

    本文转自:http://blog.chinaunix.net/uid-17079336-id-2832443.html 1.创建表的同时创建主键约束(1)无命名create table student ...

  9. UWP实现吸顶的Pivot

    话不多说,先上效果 这里使用了一个ScrollProgressProvider.cs,我们这篇文章先解析一下整体的动画思路,以后再详细解释这个Provider的实现方式. 结构 整个页面大致结构是 & ...

  10. neural_transfer风格迁移

    ContentLoss 首先是要定义一个内容差异损失函数,这里直接调用functional.mse_loss(input,self.target)就可以计算出其内容差异损失. 注意这里一般是定义一个网 ...