[Codeforces 1265E]Beautiful Mirrors
Description
一共有 \(n\) 个关卡,你初始在第一个关卡。通过第 \(i\) 个关卡的概率为 \(p_i\)。每一轮你可以挑战一个关卡。若通过第 \(i\) 个关卡,则进入第 \(i+1\) 个关卡,否则重新回到第 \(1\) 个关卡。通过第 \(n\) 个关卡则算成功。问期望多少轮游戏才能成功。
\(1\leq n\leq 2\cdot 10^5\)
Solution
设从第 \(i\) 个关卡通关的期望为 \(E_i\)。显然
\[
E_i=p_i(E_{i+1}+1)+(1-p_i)(E_1+1)
\]
特别地,\(E_{n+1}=0\),且答案为 \(E_1\)。
那么有
\[
E_1=p_1(E_2+1)+(1-p_1)(E_1+1)\Rightarrow E_1=\frac{1}{p_1}+E_2
\]
同理将上述式子代入
\[
E_2=p_2(E_3+1)+(1-p_2)(E_2+1)\Rightarrow E_1=\frac{1+\frac{1}{p_1}}{p_2}+E_3
\]
继续推导可以发现答案为
\[
E_1=\frac{1+\frac{1+\frac{1+\cdots}{p_{n-2}}}{p_{n-1}}}{p_n}
\]
Code
#include <bits/stdc++.h>
using namespace std;
const int yzh = 998244353;
int quick_pow(int a, int b) {
int ans = 1;
while (b) {
if (b&1) ans = 1ll*ans*a%yzh;
b >>= 1, a = 1ll*a*a%yzh;
}
return ans;
}
int main() {
int ans = 0, p, n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &p);
ans = (ans+1)%yzh;
ans = 1ll*ans*100%yzh*quick_pow(p, yzh-2)%yzh;
}
printf("%d\n", ans);
return 0;
}
[Codeforces 1265E]Beautiful Mirrors的更多相关文章
- Codeforces 1264C/1265E Beautiful Mirrors with queries (概率期望、DP)
题目链接 http://codeforces.com/contest/1264/problem/C 题解 吐槽:为什么我赛后看cf的题就经常1h内做出Div.1 C, 一打cf就动不动AB题不会啊-- ...
- Codeforces - 1264C - Beautiful Mirrors with queries - 概率期望dp
一道挺难的概率期望dp,花了很长时间才学会div2的E怎么做,但这道题是另一种设法. https://codeforces.com/contest/1264/problem/C 要设为 \(dp_i\ ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- 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. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- codeforces div2_604 E. Beautiful Mirrors(期望+费马小定理)
题目链接:https://codeforces.com/contest/1265/problem/E 题意:有n面镜子,你现从第一面镜子开始询问,每次问镜子"今天我是否美丽",每天 ...
- Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries
题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...
随机推荐
- redis 设置自启动
redis 设置自启动 1.创建服务(redis.conf 配置文件要注意,经过cp产生了很多个redis.conf) vim /lib/systemd/system/redis.service [U ...
- sizeof运算符和strlen()函数
首先放上代码和运行结果.(在VC6.0上运行) #include<stdio.h> #include<string.h> int main(void) { char s1[]= ...
- 通过重新上传修改后的docker镜像来在kubeapps上实现k8s上部署的nginx版本更新,回退等
docker操作:制作自定义镜像 # docker下载官方nginx镜像 docker pull nginx # 基于该镜像运行一个容器 docker run -it -d --name nginx_ ...
- Ambari深入学习(III)-开源使用及其改进思考
Ambari采用的不是一个新的思想和架构,也不是完成了软件的新的革命,而是充分利用了一些已有的优秀开源软件,巧妙地把它们结合起来,使其在分布式环境中做到了集群式服务管理能力.监控能力.展示能力.这些优 ...
- 阿里巴巴 Java 开发手册(三): 代码格式
1. [强制]大括号的使用约定.如果是大括号内为空,则简洁地写成{}即可,不需要换行:如果 是非空代码块则: 1) 左大括号前不换行. 2) 左大括号后换行. 3) 右大括号前换行. 4) 右大括号后 ...
- Golang slice和map的申明和初始化
1 前言 仅供记录使用. 2 代码 /** * @Author: FB * @Description: * @File: SliceMapInit.go * @Version: 1.0.0 * @Da ...
- SpringBoot的入门程序
1. 创建一个springboot工程 可以参考springboot入门程序 2. 创建一个实体类 @Data //想相当于@Setter.@Getter和@ToString替代了setter.get ...
- aria2 https
https://github.com/aria2/aria2/issues/361 ... and also make sure that aria2 was built with HTTPS sup ...
- mysql高级用法(1)- mariadb的主从搭建
Mariadb介绍: mariadb是mysql的一个分支,需要进一步了解的参考:https://mariadb.org/ 安装参考教程:window版安装:Mariadb 介绍 1 (安装) lin ...
- 【兼容调试】cffi library '_openssl' has no function, constant or global variable named 'Cryptography_HAS
重装cryptography就好了. conda uninstall cryptography conda install cryptography https://github.com/pyca/c ...