結果

問題 No.302 サイコロで確率問題 (2)
ユーザー parukiparuki
提出日時 2016-11-25 12:47:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,084 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 167,692 KB
実行使用メモリ 23,552 KB
最終ジャッジ日時 2024-05-05 13:23:50
合計ジャッジ時間 2,630 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 RE -
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define double long double

/***
誤差関数
erf(x) = 2/sqrt(PI) *∫(0<=t<=x, e^(-t^2))dt

標準正規分布の確率
P(0<=X<=a)
= ∫(0<=x<=a, 1/sqrt(2*PI)*e^(-x^2/2))dx
= ∫(0<=t<=sqrt(2)/2 * a, 1/sqrt(2*PI)*e^-t^2*sqrt(2))dt
= 1/2 * { 2/sqrt(PI) * ∫(0<=t<=sqrt(2)/2 * a, e^(-t)^2)dt }
= 1/2 * erf(sqrt(2)/2*a)

(x1+x2+...xn)/n
がx 以下
になる確率
***/
double centralLimitTheorem(long long n, double x, double mean, double sd) {
    double y = (x - mean) / sd * sqrt(2.0 * n) / 2;
    double res = 0;
    if(y < 0) res = 0.5 * (1 - erf(-y));
    else res = 0.5 * (1 + erf(y));
    return res;
}

double dp[1001][6001];
double f(int N, int L, int R) {
    double p = 1 / 6.0;
    rep(i, N + 1)rep(j, 6 * N + 1)dp[i][j] = 0;
    dp[0][0] = 1;
    rep(i, N)rep(j, i * 600 + 1) {
        for(int k = 1; k <= 6; ++k) {
            dp[i + 1][j + k] += dp[i][j] * p;
        }
    }
    double ans = 0;
    for(int i = L; i <= R; ++i) {
        ans += dp[N][i];
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, L, R;
    double m = 3.5;
    double sd = sqrt(35.0 / 12);
    double var = 35.0 / 12;

    while(cin >> N >> L >> R) {
        if(N > 1000) {
            double l = L ? centralLimitTheorem(N, (double)(L - 0.5) / N, m, sd) : 0;
            double r = centralLimitTheorem(N, (double)(R + 0.5) / N, m, sd);
            double ans = r - l;
            cout << setprecision(20) << ans << endl;
        } else {
            cout << setprecision(20) << f(N, L, R) << endl;
        }
    }
}
0