結果
問題 | No.75 回数の期待値の問題 |
ユーザー |
![]() |
提出日時 | 2014-11-24 18:48:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4,284 ms / 5,000 ms |
コード長 | 764 bytes |
コンパイル時間 | 515 ms |
コンパイル使用メモリ | 49,136 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-02 21:21:37 |
合計ジャッジ時間 | 89,432 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf( "%d", &K ); | ~~~~~^~~~~~~~~~~~
ソースコード
#include<cstdio> #include<ctime> #include<map> unsigned int xor128() { static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned int t = x^(x<<11); x = y; y = z; z = w; return w=(w^w>>19)^(t^(t>>8)); } std::map<int, int> m; int main() { int K; scanf( "%d", &K ); clock_t t = clock(); int total = 0; while( clock() <= t+4*CLOCKS_PER_SEC ) { int sum = 0, cnt = 0; for(;;) { int n = xor128()%6+1; sum += n; ++cnt; if( sum == K ) break; if( sum > K ) sum = 0; } ++m[cnt]; ++total; } double ans = 0; for( auto it = m.begin(); it != m.end(); ++it ) ans += (double)it->first*it->second/total; printf( "%.2f\n", ans ); return 0; }