Educational Codeforces Round 47

编程入门 行业动态 更新时间:2024-10-18 08:21:00

<a href=https://www.elefans.com/category/jswz/34/1765055.html style=Educational Codeforces Round 47"/>

Educational Codeforces Round 47

 

题目

题意:

司机不休息的话,走1公里,消耗a1,再走一公里消耗a2,然后a3、a4。这样消耗下去。

有休息站,可以让a数组重新数。

问你总消耗的期望*2^(n-1)。

 

POINT:

可以推一下。px为x这个坐标的期望组成。

p1=1*a1 (第一个永远是a1)

p2=1/2*a1+1/2*a2 (2这个点,有1/2的概率有休息站,那么1/2*a1,有1/2没有,那么从上一个点p1增加过来:

1/2*p1且下标都增加1)

p3=1/2*a1+1/4*a2+1/4*a3

可知p(y)可以从p(y-1)算出来。

答案为p1加到pn。 

 

 

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;#define  LL long longconst LL mod = 998244353;
const LL maxn = 1e6+66;
LL b[maxn];
LL a[maxn];
int main()
{LL n;scanf("%lld",&n);b[0]=1;for(LL i=1;i<=n;i++){scanf("%lld",&a[i]);b[i]=b[i-1]*2%mod;}LL pre=b[n-1]*a[1]%mod;LL ans=0;ans+=pre;for(LL i=2;i<=n;i++){pre=pre+mod-b[n-i+1]*a[i-1]%mod+b[n-i]*a[i]%mod+b[n-i]*a[i-1]%mod;pre%=mod;(ans+=pre)%=mod;}printf("%lld\n",ans);}

 

更多推荐

Educational Codeforces Round 47

本文发布于:2024-02-11 19:32:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1682948.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Educational   Codeforces

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!