链接:https://www.nowcoder.com/acm/contest/143/F
来源:牛客网

题目描述

Kanade has n boxes , the i-th box has p[i] probability to have an diamond of d[i] size.

At the beginning , Kanade has a diamond of 0 size. She will open the boxes from 1-st to n-th. When she open a box,if there is a diamond in it and it's bigger than the diamond of her , she will replace it with her diamond.

Now you need to calculate the expect number of replacements.

You only need to output the answer module 998244353.

Notice: If x%998244353=y*d %998244353 ,then we denote that x/y%998244353 =d%998244353

输入描述:

The first line has one integer n.

Then there are n lines. each line has two integers p[i]*100 and d[i].

输出描述:

Output the answer module 998244353

输入例子:
3
50 1
50 2
50 3
输出例子:
499122178

-->

示例1

输入

复制

3
50 1
50 2
50 3

输出

复制

499122178

备注:

1<= n <= 100000

1<=p[i]*100 <=100

1<=d[i]<=10^9

题意:开始手中有一个大小为0的钻石,然后给出n个箱子,有x/100的概率开出y大小的钻石,如果比手中的钻石大的话就交换,求交换次数

思路:这个牵扯到一些数学知识,我们单独算每个箱子得贡献,如果我要交换当前箱子的钻石,说明当前箱子一定要能开出钻石,所以要乘以当前得概率
然后既然当前箱子要交换,说明当前得钻石说明肯定比手中得钻石大,也就是说前面比这个箱子大得钻石都没有开出钻石,也就是要再乘以前面比它大得
钻石得失败概率,比它小的钻石开不开出钻石都不影响当前钻石,所以概率为1
所以每个箱子得贡献为: 比当前钻石大得箱子开钻石失败得概率 * 当前钻石成功概率
但是我们这样取间断的概率有点麻烦,我们这里用树状数组维护前缀积,优化了一下
我们还要注意,我们的数的范围是1e9 但是箱子的个数是1e5,
1e9的数组我们开不了,所以我们需要离散化
还有我们分数取模无法取,所以我们还要使用逆元来计算 下面看代码注释
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 998244353
using namespace std;
typedef long long ll;
struct sss
{
ll id,x;
}a[];
ll inv;
ll d[],c[];
ll n,cnt;
ll qpow(ll a,ll n)
{
ll ans=;
while(n)
{
if(n%) ans=(ans*a)%maxn;
a=(a*a)%maxn;
n>>=;
}
return ans;
}
ll lowbit(ll x)
{
return x&(-x);
}
ll sum(ll x)//因为我们要求的是比当前大的钻石概率,而模版树状数组是求小的,我们就反过来即可
{
ll ans=;
while(x<=n)
{
ans=(ans*c[x])%maxn;
x+=lowbit(x);
}
return ans;
}
void updata(ll x,ll d)//同上
{
while(x>)
{
c[x]=(c[x]*d)%maxn;
x-=lowbit(x);
}
}
int main()
{
scanf("%lld",&n);
inv=qpow(,maxn-);//计算分母100的逆元
for(int i=;i<=n;i++)
{
scanf("%lld%lld",&a[i].id,&a[i].x);
d[i-]=a[i].x;
}
sort(d,d+n);//离散化
cnt=unique(d,d+n)-d;
for(int i=;i<=n;i++)
{
c[i]=;//初始化前缀积数组
a[i].x=upper_bound(d,d+cnt,a[i].x)-d+;
}
ll ans=;
for(int i=;i<=n;i++)
{
ans = (ans + (1LL * sum(a[i].x) * a[i].id % maxn * inv)) % maxn;//把前面把他大的箱子的失败概率乘以当前成功的概率
updata(a[i].x, 1LL * ( - a[i].id)*inv % maxn);//更新树状数组 注意是100-当前概率 因为我们要存的是失败概率
}
printf("%lld",ans);
}

牛客多校第五场 F take的更多相关文章

  1. 牛客多校第五场 F take 期望转化成单独事件概率(模板) 树状数组

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 Kanade has n boxes , the i-th box has p[i] proba ...

  2. 2019牛客多校第五场 F maximum clique 1 状压dp+最大独立集

    maximum clique 1 题意 给出一个集合s,求每个子集的最大独立集的权值和(权值是独立集的点个数) 分析 n比较小,一股浓浓的暴力枚举每一个子集的感觉,但是暴力枚举模拟肯定会T,那么想一想 ...

  3. 2019牛客多校第五场F maximum clique 1 最大独立集

    题意:给你n个数,现在让你选择一个数目最大的集合,使得集合中任意两个数的二进制表示至少有两位不同,问这个集合最大是多大?并且输出具体方案.保证n个数互不相同. 思路:容易发现,如果两个数不能同时在集合 ...

  4. 牛客多校第三场 F Planting Trees

    牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...

  5. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  6. 牛客多校第四场 F Beautiful Garden

    链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...

  7. 牛客多校第五场 J:Plan

    链接:https://www.nowcoder.com/acm/contest/143/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  8. 牛客多校第五场-D-inv

    链接:https://www.nowcoder.com/acm/contest/143/D来源:牛客网 题目描述 Kanade has an even number n and a permutati ...

  9. 牛客多校第五场 E room 二分图匹配 KM算法模板

    链接:https://www.nowcoder.com/acm/contest/143/E来源:牛客网 Nowcoder University has 4n students and n dormit ...

随机推荐

  1. com.netflix.zuul.exception.ZuulException: Forwarding error

    一.问题描述 在使用Spring Cloud的zuul组件,做路由转发时,每次重新启动后端服务,头几次调用都会出现com.netflix.zuul.exception.ZuulException: F ...

  2. 20170912多线程Python爬取图片

    import threading #导入线程 from urllib import request #导入网页请求模块 import re #导入正则表达式模块 import os # 引入模块 fr ...

  3. 5 项目---自定义用户模型以及轮播图图片url返回格式

    创建自定义的用户模型类  1. 用命令创建users 应用 2. 将users 注册到settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'd ...

  4. 微信小程序 swiper 显示图片计数 当前/总数

    <view class="swiperContainer"> <swiper bindchange="swiperChange" autopl ...

  5. BottomNavigationBar使用详解

    gitHub地址:https://github.com/Ashok-Varma/BottomNavigation 一.基本使用 1.在AndroidStudio下添加依赖: compile 'com. ...

  6. pytorch初步学习(一):数据读取

    最近从tensorflow转向pytorch,感受到了动态调试的方便,也感受到了一些地方的不同. 所有实验都是基于uint16类型的单通道灰度图片. 一开始尝试用opencv中的cv.imread读取 ...

  7. STLC - 软件测试生命周期

    什么是软件测试生命周期(STLC)? 软件测试生命周期(STLC)定义为执行软件测试的一系列活动. 它包含一系列在方法上进行的活动,以帮助认证您的软件产品. 图 - 软件测试生命周期的不同阶段 每个阶 ...

  8. 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)C - Cactus Jubilee

    题意:给一颗仙人掌,要求移动一条边,不能放在原处,移动之后还是一颗仙人掌的方案数(仙人掌:无向图,每条边只在一个环中),等价于先删除一条边,然后加一条边 题解:对于一颗仙人掌,分成两种边,1:环边:环 ...

  9. Wannafly挑战赛23B游戏

    https://www.nowcoder.com/acm/contest/161/B 题意:两个人van游戏,n堆石子,每次只能取这堆石子数目的因子个数,没得取的人输,问第一个人的必胜策略有多少种 题 ...

  10. pip安装kolla-ansible时报错Cannot install 'PyYAML'的解决方法

    pip install kolla-ansible --ignore-installed PyYAML