题目链接: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 题解 组合数学的更多相关文章

  1. 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 ...

  2. Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries

    题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...

  3. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  4. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  5. 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 ...

  6. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  7. Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...

  8. Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)

    题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...

  9. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...

随机推荐

  1. 模板—tarjan求割点

    int dfn[MAXN],low[MAXN],cnt,root; bool iscut[MAXN]; void tarjan(int x) { dfn[x]=low[x]=++cnt; ; for( ...

  2. iptables SNAT与伪装

    Source NAT(SNAT)的主要應用,是让同一內部網路上的多部主机,可共用同一条Internet实体连線.直接与Internet相连的闸道器,可使用SNAT(搭配连線追蹤)来来改写內部网络与In ...

  3. 随机线性网络编码的C语言实现,实现可靠传输:原理(1)

    线性方程组,大家都不陌生吧.来一组 A11 *X1 + A12 *X2 + A13 *X3 + A14 *X4 =Q1 A21 *X1 + A22 *X2 + A23 *X3 + A24 *X4 =Q ...

  4. HTML静态网页--JavaScript-简介

    JavaScript简介 1.JavaScript是个什么东西? 它是个脚本语言,需要有宿主文件,它的宿主文件是HTML文件. 2.它与Java什么关系? 没有什么直接的联系,Java是Sun公司(已 ...

  5. phpstorm 中git 的使用

    phpstorm 是一款不可多得的IDE 环境,它既是一款强大的编辑器,还是一款调试器,同时还是一款git 可视化管理工具哟,phpers 值得拥有.今天介绍的是他不为人知的强大功能 —— git. ...

  6. js实现开关灯游戏

    需求: 点击三个按钮,页面出现不同数量的“灯” 所有的灯有相同的点击效果.点击一个灯的时候,this和他的上下左右都会变成另一种背景色. 代码在这里~~~ 文章地址 https://www.cnblo ...

  7. KMPnext数组运用、最小循环节问题

    http://www.cnblogs.com/jackge/archive/2013/01/05/2846006.html http://www.cnblogs.com/wuyiqi/archive/ ...

  8. mybatis PageHelper分页插件 和 LRU算法缓存读取数据

    分页: PageHelper的优点是,分页和Mapper.xml完全解耦.实现方式是以插件的形式,对Mybatis执行的流程进行了强化,添加了总数count和limit查询.属于物理分页. 一.首先注 ...

  9. 2019-10-7-dotnet-Framework-源代码-·-ScrollViewer

    title author date CreateTime categories dotnet Framework 源代码 · ScrollViewer lindexi 2019-10-07 13:15 ...

  10. H3C ACL包过滤显示与调试