Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
链接:
https://codeforces.com/contest/1265/problem/E
题意:
Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability pi100 for all 1≤i≤n.
Creatnx asks the mirrors one by one, starting from the 1-st mirror. Every day, if he asks i-th mirror, there are two possibilities:
The i-th mirror tells Creatnx that he is beautiful. In this case, if i=n Creatnx will stop and become happy, otherwise he will continue asking the i+1-th mirror next day;
In the other case, Creatnx will feel upset. The next day, Creatnx will start asking from the 1-st mirror again.
You need to calculate the expected number of days until Creatnx becomes happy.
This number should be found by modulo 998244353. Formally, let M=998244353. It can be shown that the answer can be expressed as an irreducible fraction pq, where p and q are integers and q≢0(modM). Output the integer equal to p⋅q−1modM. In other words, output such an integer x that 0≤x<M and x⋅q≡p(modM).
思路:
考虑期望Dp,Dp[i]是从第一天到第i天开心的期望天数。
正向推导\(Dp[i] = Dp[i-1]+ 1 * \frac{p_i}{100} + (1 - \frac{p_i}{100})*(Dp[i]+1)\)
化简得\(Dp[i] = \frac{100*(Dp[i-1]+1)}{p_i}\)
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 998244353;
const int MAXN = 2e5+10;
LL Dp[MAXN], inv;
int n;
LL ExGcd(LL a, LL b, LL &x, LL &y)
{
if (b == 0)
{
x = 1, y = 0;
return a;
}
LL d = ExGcd(b, a%b, x, y);
LL tmp = y;
y = x-(a/b)*y;
x = tmp;
return d;
}
LL GetInv(int a, int b)
{
//a*x = 1 mod b
LL d, x, y;
d = ExGcd(a, b, x, y);
if (d == 1)
return (x%b+b)%b;
return -1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
Dp[0] = 0;
int a;
for (int i = 1;i <= n;i++)
{
cin >> a;
inv = GetInv(a, MOD);
Dp[i] = 100*(Dp[i-1]+1)%MOD*inv%MOD;
}
cout << Dp[n] << endl;
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 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- 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$ 枚铜牌 ...
随机推荐
- Linux08 文件系统
对于磁盘等各类存储设备中所有的数据都以0和1的概念,但对于用户来说,0和1是没有任何意义的,这时候就需要一种类似于“翻译”的机制存在于用户和磁盘之间,Linux中采用的是文件系统+虚拟文件系统(Vir ...
- authenticate的执行流程与重写
流程 1.authenticate调用的是_get_backends函数 def authenticate(request=None, **credentials): for backend, bac ...
- quartz2.3.0(十五)执行、暂停、继续执行、清除,花式操作数据库中持久化的job任务
#################################################################################################### ...
- 保研经验帖----江西师范大学 to 华中科技大学
呼,距离拿到华科cs的offer也有一段时间,有好几次准备动手写这篇经验帖,但就是理不清自己想表达什么,今早起来状态还不错,洗漱的时候思路居然通透了,哈哈哈~ 一.基本情况 先简单介绍笔者的一些基本情 ...
- 运行时找到main方法所在的类
private Class<?> deduceMainApplicationClass() { try { StackTraceElement[] stackTrace = new Run ...
- 日志之slf4j和logback日志系统(二)
这篇文章我们讲一下,如何使用slf4j和logback组合来搭建一套日志系统. 介绍 如果我们的系统是新系统,也就是之前没有引入其他的日志工具,那么只需要引入,如果之前已经用了common-loggi ...
- Java序列化流
1.什么是序列化流 序列化就是把Java对象“流化”,序列化后的Java对象可以保存到本地文件系统,或者通过Socket传输到其他的服务器. Java中对象序列化有以下特点: 1)类实现java.io ...
- Vue项目中遇到的问题汇总
一.打包后的打开index.html页面空白的几种情况: 引入的css.js路径报错,此时解决方法:把vue.config.js中的增加publicPath: ‘./’ 或者把原来的baseUrl改为 ...
- Sbase数据库自动截断日志
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36273.1550/html/sprocs/X3 ...
- C#验证邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,IP类等常用函数封装
#region 验证邮箱验证邮箱 /**//// <summary> /// 验证邮箱 /// </summary> /// <param name="sour ...