链接:

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模块知识三 hashlib 加密模块、collections、re模块

    8.hashlib 加密模块 ​ 主要用于加密和校验 常见密文:md5,sha1,sha256,sha512 只要明文相同,密文就相同 只要明文不相同,密文就是不相同的 不能反逆(不能解密)--md5 ...

  2. flask框架(六)——闪现(get_flashed_message)、请求扩展、中间件(了解)

    message -设置:flash('aaa') -取值:get_flashed_message() -假设在a页面操作出错,跳转到b页面,在b页面显示a页面的错误信息 1 如果要用flash就必须设 ...

  3. LeetCode第8场双周赛(Java)

    这次我只做对一题. 原因是题目返回值类型有误,写的是 String[] ,实际上应该返回 List<String> . 好吧,只能自认倒霉.就当涨涨经验. 5068. 前后拼接 解题思路 ...

  4. Linux进程的五个段

    目录 数据段 代码段 BSS段 堆(heap) 栈 数据段 用来存放可执行文件中已初始化的全局变量,换句话说就是存放程序静态分配的变量和全局变量: 代码段 代码段是用来存放可执行文件的操作指令,也就是 ...

  5. 【C#】上机实验七

    .开发一个窗体应用程序,窗体上能接收华氏温度或者摄氏温度,点击相应按钮可以相互转换. 要求转换后的华氏温度或者摄氏温度保留小数点后3位,程序中要有异常处理结构. using System; using ...

  6. 宽度学习(Broad Learning System)

    宽度学习(Broad Learning System) 2018-09-27 19:58:01 颹蕭蕭 阅读数 10498  收藏 文章标签: 宽度学习BLBLS机器学习陈俊龙 更多 分类专栏: 机器 ...

  7. 3)创建,测试,发布 第一个NET CORE程序

    工具:Visual Studio Code 或者 Visual Studio 环境:.NET CORE 2.0 VS Code很强大 当然支持netcore的开发,但是我还是选择更熟悉更强大的VS. ...

  8. System.Data.Entity.Core.EntityException: 可能由于暂时性失败引发了异常。如果您在连接到 SQL Azure 数据库,请考虑使用 SqlAzureExecutionStrategy。

    代码异常描述  ************** 异常文本 **************System.Data.Entity.Core.EntityException: 可能由于暂时性失败引发了异常.如果 ...

  9. NEST health与settings

    /// <summary> /// 创建Idx,并设置分片和副本 /// </summary> public void Settings() { var response = ...

  10. 【洛谷 P4254】 [JSOI2008]Blue Mary开公司(李超线段树)

    题目链接 其实这东西很好懂的..用来维护一次函数. 每个结点存一个值,表示x=这个区间的mid时值最大的函数的编号. 把插入线段的斜率和当前结点的斜率和大小比较来更新左右儿子的值. 查询是实际上是查询 ...