题目:戳这里

思路来源:视频讲解

题意:有n个箱子按1...n标号,每个箱子有大小为di的钻石概率为pi,我们初始有个大小为0的钻石,从1到n按顺序打开箱子,遇到比手中大的箱子就换,求交换次数的数学期望。

解题思路:这题跟上题[点这里]很像,都是找到一个子状态,利用数学期望的可加性,处理求和即可。这里的子状态为每一次交换的状态,即

前j个比i大的概率积用树状数组维护。

附ac代码:

  1 #include <cstdio>
2 #include <cstdlib>
3 #include <iostream>
4 #include <cstring>
5 #include <algorithm>
6 #include <cmath>
7 #include <queue>
8 #include <vector>
9 #include <string>
10 #include <map>
11 #include <set>
12 using namespace std;
13 typedef long long ll;
14 const ll mod = 998244353;
15 const int maxn = 1e5 + 10;
16 int n;
17 struct nod
18 {
19 int id;
20 ll d;
21 ll p;
22 }bx[maxn];
23 bool cmp(nod a, nod b)
24 {
25 if(a.d > b.d) return 1;
26 else if(a.d == b.d && a.id < b.id) return 1;
27 return 0;
28 }
29 ll pmul(ll a, ll b)
30 {
31 ll res = 0;
32 while(b)
33 {
34 if(b&1)
35 res = (res + a) % mod;
36 b >>= 1;
37 a = (a + a) % mod;
38 }
39 return res;
40 }
41 ll pmod(ll a, ll b)
42 {
43 ll res = 1;
44 while(b)
45 {
46 if(b&1)
47 res = pmul(res, a) % mod;
48 b >>= 1;
49 a = pmul(a, a) % mod;
50 }
51 return res;
52 }
53 ll exgcd(ll a, ll b, ll &x, ll &y)
54 {
55 if(a == 0 && b == 0) return -1;
56 if(b == 0)
57 {
58 x = 1;y = 0;
59 return a;
60 }
61 ll d = exgcd(b, a % b, y, x);
62 y -= a/b*x;
63 return d;
64 }
65 ll mod_rev(ll a, ll n)
66 {
67 ll x, y;
68 ll d = exgcd(a, n, x, y);
69 if(d == 1) return (x % n + n) % n;
70 else return -1;
71 }
72 int lowbit(int x)
73 {
74 return x&(-x);
75 }
76 ll c[maxn * 4];
77 ll getm(int i)
78 {
79 ll s = 1;
80 while(i > 0)
81 {
82 s = pmul(s , c[i]) % mod;
83 i -= lowbit(i);
84 }
85 return s;
86 }
87 void add(int i, ll val)
88 {
89 while(i <= n)
90 {
91 c[i] = pmul(c[i], val) %mod;
92 i += lowbit(i);
93 }
94 }
95 int main()
96 {
97
98 ll inv = mod_rev(100ll, mod);
99 // printf("%lld\n", inv);
100 scanf("%d", &n);
101 for(int i = 0; i < maxn; ++i)
102 c[i] = 1;
103 for(int i = 1; i <= n; ++i)
104 {
105 scanf("%lld %lld", &bx[i].p, &bx[i].d);
106 bx[i].id = i;
107 }
108 sort(bx + 1, bx + 1 + n, cmp);
109
110 ll ans = 0;
111 for(int i = 1; i <= n; ++i)
112 {
113 // printf("%lld\n", getm(bx[i].id));
114 //printf("%lld %lld %d\n", bx[i].p, bx[i].d, bx[i].id);
115 ans = (ans + getm(bx[i].id) * bx[i].p % mod * inv % mod) % mod;
116 add(bx[i].id, ((100 - bx[i].p) * inv) % mod);
117 }
118 printf("%lld\n", ans);
119 }

牛客网多校第5场 F take 【思维+数学期望】的更多相关文章

  1. 牛客网多校训练第一场 F - Sum of Maximum(容斥原理 + 拉格朗日插值法)

    链接: https://www.nowcoder.com/acm/contest/139/F 题意: 分析: 转载自:http://tokitsukaze.live/2018/07/19/2018ni ...

  2. 牛客网多校第3场C-shuffle card 平衡树或stl(rope)

    链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...

  3. 牛客网多校第3场Esort string (kmp)

    链接:https://www.nowcoder.com/acm/contest/141/E 来源:牛客网 题目描述 Eddy likes to play with string which is a ...

  4. 牛客网多校赛第九场A-circulant matrix【数论】

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

  5. 牛客网多校训练第二场D Kth Minimum Clique

    链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...

  6. 牛客网多校第5场 H subseq 【树状数组+离散化】

    题目:戳这里 学习博客:戳这里 题意:给n个数为a1~an,找到字典序第k小的序列,输出该序列所有数所在位置. 解题思路:先把所有序列预处理出来,方法是设一个数组为dp,dp[i]表示以i为开头的序列 ...

  7. 牛客网多校第5场 I vcd 【树状数组+离散化处理】【非原创】

    题目:戳这里 学习博客:戳这里 作者:阿狸是狐狸啦 n个点,一个点集S是好的,当且仅当对于他的每个子集T,存在一个右边无限延长的矩形,使的这个矩形包含了T,但是和S-T没有交集. 求有多少个这种集合. ...

  8. 牛客网多校第4场 J Hash Function 【思维+并查集建边】

    题目链接:戳这里 学习博客:戳这里 题意: 有n个空位,给一个数x,如果x%n位数空的,就把x放上去,如果不是空的,就看(x+1)%n是不是空的. 现在给一个已经放过数的状态,求放数字的顺序.(要求字 ...

  9. 牛客网多校第4场 A.Ternary String 【欧拉降幂】

    题目:戳这里 学习博客:戳这里 欧拉函数的性质: ① N是不为0的整数.φ(1)=1(唯一和1互质的数就是1本身) ② 除了N=2,φ(N)都是偶数. ③ 小于N且与N互质的所有数的和是φ(n)*n/ ...

随机推荐

  1. Poj-P2533题解【动态规划】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: http://poj.org/problem?id=2533 题目描述: 如果ai1 < ...

  2. 1.8V转3V,1,8V转3.3V电源芯片的规格书参数

    1.8V电平如何稳压稳定输出3V或者3.3V,就需要用到1.8V转3V,1,8V转3.3V电源芯片,就PW5100(低功耗,外围简单),PW5200A是可调输出电压,可以输出电压根据外围电阻来设置命令 ...

  3. 2020 CSP&NOIP 游记

    CSP初赛 CSP初赛 Day -1 早上打了模拟赛,T2寒假正好做过,然而还是还是被踩Orz,郑外NB!.中午出校吃了大盘鸡和拉面,还带回来了三瓶可乐. 初赛知识点看了两页不(看)想(不)看(懂)了 ...

  4. 从零开始学spring源码之ioc预热:bean的拓展和beanProcessor注册

    上篇聊完了bean的解析,说起来做的事情很简单,把xml文件里面配置的标签全部解析到spring容器里面,但是spring做的时候,花了那么大代价去做,后面看看到底值不值得呢. 接下来看看prepar ...

  5. jemeter断言和性能分析

    一.添加断言 1.原因:检查是否有该结果,一般一个请求过去除了400和500的只要通过的都会代表请求成功,比如登录页面及时填写了错误密码,虽然会返回密码错误,但这个请求还是成功的,所以我们要添加断言, ...

  6. Spring框架入门浅析

    一.Spring Bean的配置 在需要被Spring框架创建对象的实体类的类声明前面加注解:```@component```.这样在Spring扫描的时候,看到该注解就会在容器中创建该实体类的对象. ...

  7. gin框架之路由前缀树初始化分析

    https://mp.weixin.qq.com/s/lLgeKMzT4Q938Ij0r75t8Q

  8. Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe.

    Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe. htt ...

  9. (Oracle)导出表结构

    DECLARE cursor t_name is SELECT rank() over(order by a.TABLE_NAME) as xiaolonglong,a.TABLE_NAME FROM ...

  10. RMI笔记

    这是<java核心技术> 第11章 分布式对象的笔记. RMI基本原理 我们使用远程方法调用是希望达到这样的目的: 可以像调用本地方法一样去调用一个远程方法. 实现远程调用的方式是 为客户 ...