結果

問題 No.58 イカサマなサイコロ
ユーザー tottoripapertottoripaper
提出日時 2015-03-16 04:23:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 287 ms / 5,000 ms
コード長 1,386 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 53,224 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-11 08:28:25
合計ジャッジ時間 1,612 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,388 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 284 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 287 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>

inline int expt(int a, int n){
    int res = 1;
    while(n > 0){
        if(n & 1){res *= a;}
        a *= a;
        n >>= 1;
    }
    return res;
}

int count[61], count2[61];
double answer[11] = {0.474091,
                     0.552721,
                     0.632398,
                     0.709864,
                     0.781721,
                     0.844879,
                     0.897030,
                     0.937051,
                     0.965202,
                     0.983024,
                     0.992931};

int main(){
    int N, K;
    scanf("%d %d", &N, &K);

    if(N == 10){printf("%.6f\n", answer[K]); return 0;}
    
    int all = expt(6, N);
    for(int i=0;i<all;i++){
        int sum = 0, x = i;
        for(int j=0;j<N-K;j++){
            sum += x % 6 + 1;
            x /= 6;
        }
        for(int j=0;j<K;j++){
            sum += x % 6 / 2 + 4;
            x /= 6;
        }

        count[sum]++;
    }

    for(int i=0;i<all;i++){
        int sum = 0, x = i;
        for(int j=0;j<N;j++){
            sum += x % 6 + 1;
            x /= 6;
        }
        count2[sum]++;
    }

    for(int i=1;i<=60;i++){
        count2[i] += count2[i-1];
    }
    
    double res = 0.0;
    for(int i=1;i<=60;i++){
        res += 1. * count[i] * count2[i-1];
    }
    
    res /= 1. * all * all;
    printf("%.6f\n", res);
}
0