結果
問題 | No.58 イカサマなサイコロ |
ユーザー |
![]() |
提出日時 | 2015-03-16 04:23:17 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 248 ms / 5,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 611 ms |
コンパイル使用メモリ | 55,000 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 23:04:05 |
合計ジャッジ時間 | 1,419 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d %d", &N, &K); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#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); }