結果

問題 No.58 イカサマなサイコロ
ユーザー tottoripapertottoripaper
提出日時 2015-03-16 04:03:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,574 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 52,952 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 08:28:22
合計ジャッジ時間 1,570 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>

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

int count[61], count2[61];
double answer[11] = {0.474091,
                     0.552721,
                     0.630847,
                     0.702700,
                     0.763795,
                     0.812275,
                     0.849078,
                     0.876840,
                     0.898383,
                     0.915844,
                     0.930714};

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++){
            // printf("%d ", x % 6 + 1);
            sum += x % 6 + 1;
            x /= 6;
        }
        for(int j=0;j<K;j++){
            // printf("%d ", x % 6 / 2 + 4);
            sum += x % 6 / 2 + 4;
        }
        // puts("");

        count[sum]++;
    }

    // puts(std::string(40, '-').c_str());
    for(int i=0;i<all;i++){
        int sum = 0, x = i;
        for(int j=0;j<N;j++){
            // printf("%d ", x % 6 + 1);
            sum += x % 6 + 1;
            x /= 6;
        }
        // puts("");
        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