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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【HDU - 6574】Rng(概率,古典概型)

發(fā)布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 6574】Rng(概率,古典概型) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

Avin is studying how to synthesize data. Given an integer n, he constructs an interval using the following method: he first generates a integer r between 1 and n (both inclusive) uniform-randomly, and then generates another integer l between 1 and r (both inclusive) uniform-randomly. The interval [l, r] is then constructed. Avin has constructed two intervals using the method above. He asks you what the probability that two intervals intersect is. You should print p*?q(?1)q(?1)(MOD 1, 000, 000, 007), while?pqpq?denoting the probability.

Input

Just one line contains the number n (1 ≤ n ≤ 1, 000, 000).

Output

Print the answer.

Sample Input

1 2

Sample Output

1 750000006

題目大意:

給定長度為n的區(qū)間,定義產(chǎn)生一個區(qū)間[l,r]的方式:第一次在[1,n]內(nèi)等概率選一個點當做r,然后在[1,r]內(nèi)等概率選一個點當l。

如此產(chǎn)生兩個區(qū)間,問這兩個區(qū)間相交(應該是指的有交點)的概率是多大?

解題報告:

對右端點分成三種情況,因為是古典改性直接用乘法原理計算對應事件發(fā)生的概率;累加即可。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; const ll mod = 1e9 + 7; int n; ll qpow(ll a,ll b){ll res=1;while(b) {if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res; } int main() {while(~scanf("%d",&n)){printf("%lld\n",(n+1)*qpow(2*n,mod-2)%mod);}return 0; }

?

總結

以上是生活随笔為你收集整理的【HDU - 6574】Rng(概率,古典概型)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。