题目链接: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. @总结 - 10@ Miller-Rabin素性测试与Pollard-Rho因数分解

    目录 @1 - 素性测试:Miller-Rabin算法@ @1.1 - 算法来源@ @1.2 - 算法描述@ @1.3 - 算法实现@ @2 - 因数分解:Pollard-Rho算法@ @2.0 - ...

  2. @codeforces - 631E@ Product Sum

    目录 @desription@ @solution@ @accepted code@ @details@ @desription@ 给定一个序列 a,定义它的权值 \(c = \sum_{i=1}^{ ...

  3. git 本地仓库操作

    一.git对象模型和存储 二.常用命令 1)git checkout branch 切换分支 假设现在有两个分支,master和dev分支 i dev分支上没有readme.txt 在master分支 ...

  4. hdu 3466 Proud Merchants(有排序的01背包)

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  5. origin/HEAD -> origin/master 这个分支是干嘛的啊

    ➜ sso git:(master) ✗ git branch -r origin/4.0 origin/HEAD -> origin/master origin/master origin/H ...

  6. HOSt ip is not allowed to connect to this MySql server, MYSQL添加远程用户或允许远程访问三种方法

    HOSt ip is not allowed to connect to this MySql server 报错:1130-host ... is not allowed to connect to ...

  7. [转]React入门看这篇就够了

    摘要: 很多值得了解的细节. 原文:React入门看这篇就够了 作者:Random Fundebug经授权转载,版权归原作者所有. React 背景介绍 React 入门实例教程 React 起源于 ...

  8. springboot jpa 解决延迟加载问题

    在springboot中,在application.properties的配置文件中新增spring.jpa.open-in-view=true方法失效,经过测试,有两种解决办法: 1.在applic ...

  9. H3C ACL包过滤的局限性

  10. thinkphp3.2如何自动生成后台模块并且怎么访问

    https://blog.csdn.net/whulovely/article/details/72773729 步骤一:在入口文件index.php下绑定Admin模块(这时候别再Home同级手动创 ...