题目:戳这里

思路来源:视频讲解

题意:有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. 1V转3.3V稳压供电的芯片电路图

    1V转3.3V供电是简单的,仅需要一个芯片和三个外围元件即可组成这样的一个1V转3.3V的电路图和升压电路了.可以持续稳定地供电3.3V给模块或者MCU灯电路.让后端工作稳定,同时也能控制电路的功耗. ...

  2. SQLHelper ------ python实现

    SQLHelper ------ python实现 1.第一种: import pymysql import threading from DBUtils.PooledDB import Pooled ...

  3. Spark底层原理详细解析(深度好文,建议收藏)

    Spark简介 Apache Spark是用于大规模数据处理的统一分析引擎,基于内存计算,提高了在大数据环境下数据处理的实时性,同时保证了高容错性和高可伸缩性,允许用户将Spark部署在大量硬件之上, ...

  4. 分布式事务 Seata Saga 模式首秀以及三种模式详解 | Meetup#3 回顾

    https://mp.weixin.qq.com/s/67NvEVljnU-0-6rb7MWpGw 分布式事务 Seata Saga 模式首秀以及三种模式详解 | Meetup#3 回顾 原创 蚂蚁金 ...

  5. java面向对象(二)构造函数和构造代码块

    面向对象 类成员 1.成员变量 属性 数值类型的基本数据类型默认值是 0 成员变量在任何方法中都能访问,和声明先后没有关系 2.成员函数 方法 3.定义方式 class 类名{成员变量:成员函数} / ...

  6. openrstry 限流 是否有清零逻辑 连接池

    openrstry  限流  是否有清零逻辑 https://github.com/openresty/lua-resty-limit-traffic # encoding=utf-8 # Shawn ...

  7. Python的交互模式和直接运行.py文件有什么区别

    使用文本编辑器 - 廖雪峰的官方网站 https://www.liaoxuefeng.com/wiki/1016959663602400/1017024645952992 直接输入python进入交互 ...

  8. scala之map,List,:: , +:, :+, :::, +++操作

    scala之map,List操作 1.Map操作 2.List操作 2.1Demo1 2.2Demo2 3.:: , +:, :+, :::, +++ 1.Map操作 Map(映射)是一种可迭代的键值 ...

  9. Centos7安装成功后,网卡配置及更改镜像地址为国内镜像

    Centos7安装成功后,网卡配置及更改镜像地址为国内镜像 一.网卡配置 二.修改网络配置 踩坑一:IPADDR 踩坑二:网关,DNS与本地不一致 重启网络服务 三.镜像修改为aliyun 四.相关知 ...

  10. Cookie (设置与读取、超时设置、指定路径、显示用户上次登录时间)

    Cooike简介 Cookie 是在 HTTP 协议下,服务器或脚本可以维护客户工作站上信息的一种方式.Cookie 是由 Web 服务器保存在用户浏览器(客户端)上的小文本文件,它可以包含有关用户的 ...