結果
問題 | No.302 サイコロで確率問題 (2) |
ユーザー |
|
提出日時 | 2021-09-10 21:07:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,914 ms / 6,000 ms |
コード長 | 2,148 bytes |
コンパイル時間 | 2,206 ms |
コンパイル使用メモリ | 195,848 KB |
最終ジャッジ日時 | 2025-01-24 09:19:50 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=(n)-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=2e9+1; const ll INF=4e18; const ll dy[8]={-1,0,1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } using ld=double; ld f(ld x){//標準正規分布のxの値 return expl(-x*x/2)/sqrtl(acosl(-1.0)*2); } ld simpson(ld x0,ld x_max){ ll n=1000000; ld delta = (x_max - x0)/n; ld a; a = f(x0); a += f(x0 + delta * n); int i; for(i=1; i<n; i+=2){ a += f(x0 + delta * i) * 4; } for(i=2; i<n; i+=2){ a += f(x0 + delta * i) * 2; } return a*delta/3.0; } ld calc(ld m,ld s,ld a,ld b){//平均m,標準偏差sの確率変数Xがa<X<bとなる確率 a=max((a-m)/s,(ld)-10.0); b=min((b-m)/s,(ld)10.0); //ld width=(b-a)/10000000; //cout << width << endl; return simpson(a,b); /*ld ans=0; for(ld x=a;x<=b;x+=width)ans+=width*phi(x+width/2); return ans;*/ } int main(){ ll n,l,r;cin >> n >> l >> r; chmax(l,n);chmin(r,n*6); CST(10); if(n>20000){ ld m=3.5*n; ld s=35.0*n;s/=12;s=sqrtl(s); cout << calc(m,s,l,r) << endl; } else{ vector<ld> dp={1}; rep(i,n){ vector<ld> ndp((i+1)*6+2); rep(j,dp.size()){ if(dp[j]<1e-10)continue; rep(k,6)ndp[j+k+1]+=dp[j]/6; } swap(dp,ndp); } ld ans=0; for(ll i=l;i<=r;i++)ans+=dp[i]; cout << ans << endl; } }