Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E
题目大意:
有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只有成功了才会进入下一步,失败了会从第 \(1\) 步重新开始测。请问成功的期望步数是多少?
解题思路:
设期望步数是 \(S\) ,则有公式如下:

实现代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200020;
const ll MOD = 998244353LL;
void gcd(ll a , ll b , ll &d , ll &x , ll &y) {
if(!b) {d = a; x = 1; y = 0;}
else { gcd(b , a%b,d,y , x); y -= x * (a/b); }
}
ll inv(ll a , ll n) {
ll d , x , y;
gcd(a , n , d, x , y);
return d == 1 ? (x+n)%n : -1;
}
int n;
ll a[maxn], p[maxn], s[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
for (int i = 1; i <= n; i ++) {
p[i] = a[i] * inv(100, MOD) % MOD;
}
s[0] = 1;
for (int i = 1; i <= n; i ++) s[i] = s[i-1] * p[i] % MOD;
ll x = 0, y = 0;
for (int i = 1; i <= n; i ++) {
x = (x + s[i-1] * (1 - p[i] + MOD) % MOD) % MOD;
y = (y + s[i-1] * (1 - p[i] + MOD) % MOD * i % MOD) % MOD;
}
y = (y + s[n] * n % MOD) % MOD;
x = (1 - x + MOD) % MOD;
ll res = y * inv(x, MOD) % MOD;
printf("%lld\n", res);
return 0;
}
Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学的更多相关文章
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...
- Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries
题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)
题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...
随机推荐
- 21Hash算法以及暴雪Hash
一:哈希表简介 哈希表是一种查找效率极高的数据结构,理想情况下哈希表插入和查找操作的时间复杂度均为O(1),任何一个数据项可以在一个与哈希表长度无关的时间内计算出一个哈希值(key),然后在常量时间内 ...
- 利用阿里云容器服务打通TensorFlow持续训练链路
本系列将利用Docker和阿里云容器服务,帮助您上手TensorFlow的机器学习方案 第一篇:打造TensorFlow的实验环境 第二篇:轻松搭建TensorFlow Serving集群 第三篇:打 ...
- @codechef - BIKE@ Chef and Bike
目录 @description@ @solution@ @accepted code@ @details@ @description@ 输入 n(n ≤ 22) 个点,m(m ≤ 8000) 个边.每 ...
- hdu 1839 Delay Constrained Maximum Capacity Path(spfa+二分)
Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65 ...
- 2019南昌网络赛-I. Yukino With Subinterval 线段树套树状数组,CDQ分治
TMD...这题卡内存卡的真优秀... 所以以后还是别用主席树的写法...不然怎么死的都不知道... 树套树中,主席树方法开权值线段树...会造成空间的浪费...这道题内存卡的很紧... 由于树套树已 ...
- C++ 结构体的定义
struct 结构体名称{ 数据类型 A: 数据类型 B; }结构体变量名; 相当于: struct 结构体名称{ 数据类型 A: 数据类型 B; }; struct 结构体名 ...
- ubuntu14.04 dnsmasq搭建本地名字服务器
1 修改dnsmasq配置文件/etc/dnsmasq.conf 在/etc/dnsmasq.conf文件底部增加 #++++++++++++++++++++++++++++++++++++++++ ...
- spring boot与activiti集成实战 转
为什么80%的码农都做不了架构师?>>> 这是原作者的博客地址 http://wiselyman.iteye.com/blog/2285223 代码格式混乱,我修正了一下.项目源码在 ...
- 基于thinkphp实现根据用户ip判断地理位置并提供对应天气信息的应用
https://blog.csdn.net/MyCodeDream/article/details/46706469 我们都知道,在很多的网站都提供了给用户提供天气预报的功能,有时会发现,用户即使不输 ...
- springboot 实现 aop
pom.xml 导入 springboot aop 依赖 <dependency> <groupId>org.springframework.boot</groupId& ...