CodeForces 1265E Beautiful Mirrors(数学期望)

Beautiful Mirrors

time limit per test:2 seconds
memory limit per test:256 megabytes
Problem Description

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 p i 100 \frac{pi}{100} 100pi for all 1in.

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.
Input

The first line contains one integer n (1 ≤ n ≤ 2⋅105) — the number of mirrors.

The second line contains n integers p1,p2,…,pn (1≤pi≤100).

Output

Print the answer modulo 998244353 in a single line.

Sample Input

1
50

Sample Output

2

题意

n个镜子,每个镜子有 p i 100 \frac{pi}{100} 100pi的概率回答是,初始从1开始,如果询问镜子回答为是,则下一天将询问第i+1个镜子,当第n个镜子回答是时,游戏结束。如果镜子回答为否,则下一天将重新访问第1个镜子。求游戏结束的期望步数。

题解:

期望题。需要求第n个物品回答为是的期望步数,则肯定需要知道它有机会进行回答的期望步数step,然后单独考虑n,它需要100/an次才能回答为是,两者结合考虑,就能得出第n步回答为是的期望步数为 ( s t e p + 1 ) ∗ 100 a n (step+1)*\frac{100}{a_n} (step+1)an100。(至于为什么+1,当然是因为它自己回答的这一步本身也是需要计算的啊)。同理,也可以得到第i个回答为是的期望步数,从1推到n就好了。

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctype.h>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<iostream>
#include<iterator>
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define INF 0x3f3f3f3f
#define eps 1e-8
 
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 200100;
const int mod = 998244353;
int a[maxn];
LL Pow(LL a, LL b);

int main()
{
	int n, i, j;
	LL ans = 0;
	scanf("%d", &n);
	for(i=1;i<=n;i++){
		scanf("%d", &a[i]);
		//求单独考虑i,它回答是的期望步数
		LL p = 100*Pow(a[i], mod-2)%mod;
		ans = (ans + 1)*p%mod;
	}
	printf("%lld\n", ans);	
	return 0;
}

LL Pow(LL a, LL b)
{
	LL n=1;
	while(b)
	{
		if(b%2)n = n*a%mod;
		a = a*a % mod;
		b /= 2;
	}
	return n;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值