题意

总共有 $n$ 层楼,在第 $i$ 层花费 $a_i$ 的代价,有 $pi$ 的概率到 $i+1$ 层,否则到 $x_i$($x_i \leq 1$) 层。接下来有 $q$ 次询问,每次询问 $l$ 层到 $j$ 层的期望代价。

分析

这种期望具有可加性,因此,维护一个前缀和 $sum[i]$:从 $1$ 到 $i$ 的期望。

设从 $i$ 到 $i+1$ 的期望代价为 $E$,则有

$E = a_i + (1-\frac{r_i}{s_i})(sum[i]-sum[x_i]+E)$

解得 $E = [s_ia_i + (s_i-r_i)(sum[i]-sum[x_i])]/r_i$

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const ll mod = 1e9 + ;
const int maxn = + ;
ll sum[maxn];
int n, q; ll qpow(ll a, ll b)
{
ll ret = ;
while(b)
{
if(b&) ret = ret * a % mod;
a = a *a % mod;
b >>= ;
}
return ret;
}
ll inv(ll x)
{
return qpow(x, mod-);
} //第i层到第i+1层的期望
void getE(ll i, ll ri, ll si, ll ai, ll xi)
{
ll e = si * ai % mod;
e = (e + (si - ri) * (sum[i] - sum[xi]) % mod);
e = e * inv(ri) % mod;
e = (e + mod) % mod;
sum[i+] = (sum[i] + e) % mod;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &q);
for(int i = ;i <= n;i++)
{
ll ri, si, xi, ai;
scanf("%lld%lld%lld%lld", &ri, &si, &xi, &ai);
getE(i, ri, si, ai, xi);
} for(int i = ;i < q;i++)
{
int l, r;
scanf("%d%d", &l, &r);
printf("%lld\n", (sum[r] - sum[l] + mod) % mod);
}
}
}

参考链接:https://blog.csdn.net/mmk27_word/article/details/99472953

2019杭电多校第七场 HDU - 6656 Kejin Player——概率&&期望的更多相关文章

  1. [2019杭电多校第七场][hdu6656]Kejin Player

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意为从i级花费a元有p的概率升到i+1级,有1-p的概率降到x级(x<i),查询从L级升 ...

  2. [2019杭电多校第七场][hdu6655]Just Repeat

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 题意是说两个人都有一些带有颜色的牌,两人轮流出牌,但是不能出对面出过的颜色的牌,最后谁不能出牌谁 ...

  3. [2019杭电多校第七场][hdu6651]Final Exam

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6651 题意:n个科目,总共m分,通过一科需要复习花费科目分数+1分钟,在不知道科目分数的情况下,问最少 ...

  4. [2019杭电多校第七场][hdu6646]A + B = C(hash)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6646 题意为求a*10x+b*10y=c*10z满足公式的任意一组解x,y,z. 因为c有可能会由a+ ...

  5. 2019 杭电多校第八场 HDU - 6665 Calabash and Landlord 两矩形分平面

    题意 给出两个矩形,问这两个矩形把平面分成了几部分. 分析 不需要什么高级技能,只需 “简单” 的分类讨论. (实在太难写了,对拍找出错误都不想改 推荐博客,其中有个很好的思路,即只讨论答案为2,3, ...

  6. 杭电多校第七场 1010 Sequence(除法分块+矩阵快速幂)

    Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your ...

  7. 杭电多校第七场-J-Sequence

    题目描述 Let us define a sequence as belowYour job is simple, for each task, you should output Fn module ...

  8. hdu61272017杭电多校第七场1008Hard challenge

    Hard challenge Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

  9. 2017杭电多校第七场1011Kolakoski

    Kolakoski Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Tota ...

随机推荐

  1. (模板)AC自动机模板

    模板1. 给出模式串和文本串,文本串长度小于1e6,模式串长度之和小于1e6,求文本串中有多少模式串出现. 题目链接:https://www.luogu.org/problem/P3808 AC co ...

  2. LeetCode 172. 阶乘后的零(Factorial Trailing Zeroes)

    172. 阶乘后的零 172. Factorial Trailing Zeroes 题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量. LeetCode172. Factorial Trai ...

  3. QT 创建一个线程播放监控视频

    1.创建一个线程类(PlayVideoThread): PlayVideoThread.h头文件 #pragma once #include <QObject> #include &quo ...

  4. dedecms5.7怎么安装百度编辑器

    用过dedecms的朋友都知道dede自带的文本编辑器很不好用,且有些功能还需要我们自己手动去修改源码,才能完成我们想要的效果.现在广大用dedecms的朋友们,你们有福啦!我们可以利用百度的Uedi ...

  5. 图像处理库 Pillow与PIL

    PIL只支持python2的版本到2.7: Python imaging Library : Pillow 是PIL派生的一个分支,支持3以上Python版本. 命令使用pip安装: pip inst ...

  6. error: snap "eclipse" has "install-snap" change in progress

    在Ubuntu 18.04使用snap安装eclipse软件报时错: inuxidc@linuxidc:~$ snap install --classic eclipse error: snap &q ...

  7. 题解-AtCoder ARC-083F Collecting Balls

    Problem ARC083F 题意概要:给定 \(2n\) 个二维平面上的球,坐标分别为 \((x_i,y_i)\),并给出 \(n\) 个 \(A\)类 机器人 和 \(n\) 个 \(B\)类 ...

  8. centos6克隆虚拟机后,网络无法访问和启动

    使用vmware安装centos6虚拟机时, 克隆虚拟机后无法访问网络. 原因是:产生了重复的网卡信息** 克隆后在70-persistent-net.rules文件中会多一行网卡信息,把第一行网卡信 ...

  9. mac os安装mtr

    MTR是Linux平台上一款非常好用的网络诊断工具,集成了traceroute.ping.nslookup的功能,用于诊断网络状态非常有用 现使用的方法是下载pkg包手动安装 mtr的pkg下载地址 ...

  10. JS权威指南读书笔记(二)

    第四章 表达式和运算符 1 new调用构造函数的过程     a 创建一个新的空对象     b 设置空对象的_proto_指向构造函数原型prototype     c 将这个新对象当做this的值 ...