日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

take

發布時間:2023/12/3 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 take 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

take
題解參考

題目描述

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
示例1
輸入
復制

3 50 1 50 2 50 3

輸出
復制

499122178

備注:

1<= n <= 100000

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

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

題意:

有n個箱子,第i個盒子具有p [i]大小為d [i]的鉆石的概率。
從1號開始依次打開,如果比手中的寶石大就替換它,計算期望的更換次數
(一開始默認手中鉆石為0)

題解:

一旦扯到概率我就感覺好復雜。。。
首先我們要知道期望有可加性的,也就是E(X+Y)=E(X)+E(Y)
所以,所有交換次數的期望就等于每個寶箱打開后交換次數的期望和,而當個寶箱交換次數無非是0或1(即交換與不交換),所以如果一個寶箱能夠產生交換次數的話,就會對答案產生貢獻了
所以我們就要去看每一個寶箱到底能否做出貢獻,這怎么看?交換的情況是當前的寶石更大,但是在此寶箱之前可以有更大的寶石,那我們就要使該寶箱打開后不出現寶石就可以了
總結下,對于每個寶箱,我們使在其之前擁有比當前寶箱更大的鉆石的寶箱打開后不出現鉆石


式子如圖
如果來

代碼:

#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod=998244353; const int maxn=1e5+10; int c[maxn]; struct node {int d,id;ll p;bool operator<(const node &a)const{if(d==a.d) return id<a.id;return d>a.d;} }q[maxn];int lowbit(int x) {return x&(-x); } void add(int p,ll v) {while(p<=maxn){c[p]=(c[p]*v)%mod;p+=lowbit(p);} }ll sum(int p) {ll res=1;while(p){res=(res*c[p])%mod;p-=lowbit(p);}return res; }ll quickpow(ll a,ll b,ll m) {a=a%m;ll ans=1;while(b){if(b&1) ans=(ans*a)%mod;b>>=1;a=(a*a)%mod;}return ans; } int main() {int n;scanf("%d",&n);ll inv=quickpow(100,mod-2,mod);for(int i=1;i<=maxn;i++) c[i]=1;for(int i=1;i<=n;i++){scanf("%lld %d",&q[i].p,&q[i].d);q[i].p=(q[i].p*inv)%mod;q[i].id=i;}sort(q+1,q+n+1);ll ans=0;for(int i=1;i<=n;i++){ans=(ans+(1LL*sum(q[i].id)*q[i].p%mod))%mod;add(q[i].id,(1-q[i].p+mod)%mod);}printf("%lld\n",ans); }

總結

以上是生活随笔為你收集整理的take的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。