链接: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. 整理用Java实现数字转化成字符串左边自动补零方法

    Java 中给数字左边补0 (1)方法一 import java.text.NumberFormat; public class NumberFormatTest { public static vo ...

  2. 3、K-近邻算法

    K最近邻(k-Nearest Neighbor,KNN)分类算法 1.定义:如果一个样本在特征空间中的k个最近似(即特征空间中最临近)的样本中大多数属于某一类别,则该样本也属于这个类别. 2.计算公式 ...

  3. Go中的结构体

    前面我们或多或少的都使用了结构体这种数据结构,本身结构体也有很多特性,我们一一来看. 结构体的作用是将一个或者多个任一类型的变量组合在一起的数据类型,类似于我们在Java中class的作用.在结构体重 ...

  4. 自定义markdown代码高亮显示-cnblog

    这个代码高亮..一点儿都不高亮...... cnblog里已经有闻道先者贴出代码了, https://www.cnblogs.com/liutongqing/p/7745413.html 效果大概是这 ...

  5. 史上最全面的SignalR系列教程-2、SignalR 实现推送功能-永久连接类实现方式

    1.概述 通过上篇史上最全面的SignalR系列教程-1.认识SignalR文章的介绍,我们对SignalR技术已经有了一个全面的了解.本篇开始就通过SignalR的典型应用的实现方式做介绍,例子虽然 ...

  6. viewpager_轮播

    public class MainActivity extends Activity { private ViewPager pager; private int[] id={R.layout.lay ...

  7. MySQL学习随笔记录

    安装选custmer自定义安装.默认安装全部在c盘.自定义安装的时候有个advance port选项用来选择安装目录. -----------------------MySQL常见的一些操作命令--- ...

  8. Java学习|多线程学习笔记

    什么是线程?     可以理解为进程中独立运行的字任务.   使用多线程:     1.继承Thread类:从源码可以看到,Thread累实现了Runnable接口.         如果多次调用st ...

  9. 重学计算机组成原理(七)- 程序无法同时在Linux和Windows下运行?

    既然程序最终都被变成了一条条机器码去执行,那为什么同一个程序,在同一台计算机上,在Linux下可以运行,而在Windows下却不行呢? 反过来,Windows上的程序在Linux上也是一样不能执行的 ...

  10. JDK基础必备面试十问

    1. new一个对象在Java内部做了哪些工作? 从静态角度来看,new一个对象表示创建一个类的对象实例. 从JVM运行角度来看,当JVM执行到new字节码时,首先会去查看类有没有被加载到内存以及初始 ...