链接:

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的更多相关文章

  1. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  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. python 安装pytorch 及 安装失败解决办法

    python 安装pytorch 及 安装失败解决办法 [转] pytorch安装失败解决办法 [转] 一分钟在win10终端成功安装pytorch pytorch 的安装方法有2种,一种是pip安装 ...

  2. Docker简易安装及命令实例

    docker ~ ~ ~ Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中, ...

  3. tkinter学习笔记_02

    4. 多行输入框 text # 按钮 # command 执行动作 def insert_point(): var = e.get() t.insert('insert', var) b = tk.B ...

  4. mybatis 多个中间表查询映射

    最近项目用到中间表,则遇到如何联查映射的问题,之前一直都是一个表头,多个明细或者一对一这样的关系,没遇到这样的问题,所以趁机找了下资料解决了这个问题. 表结构设计如下: 主表: CREATE TABL ...

  5. C#学习笔记------参数

    一.形参 形参是本地变量,它声明在方法的参数列表中,而不是方法体中.

  6. C# 数组排序带索引

    想到了两种方法来实现,分别利用了List.Sort()和Dictionary.OrderBy()方法,代码如下: , , , , , , , , , }; //List.Sort() List< ...

  7. weui中的picker使用js进行动态绑定数据

    解决方案; picker和Select组件是通过input标签绑定,可以先通过input的父级元素移除input标签,重新插入input标签,最后重新初始化picker或Select组件. <d ...

  8. Oracle数据库的视图

    使用视图的优点:    1.简化数据操作:视图可以简化用户处理数据的方式.    2.着重于特定数据:不必要的数据或敏感数据可以不出现在视图中.    3.视图提供了一个简单而有效的安全机制,可以定制 ...

  9. uboot使用脚本

    使用mkimage命令 # mkimage -A ARM -O linux -T script -C none -n "script" -d *.sh *.img # tftp x ...

  10. 查看域名https证书到期时间

    1.通过域名获取: echo | openssl s_client -servername 域名 -connect 域名:443 2>/dev/null | openssl x509 -noou ...