結果
| 問題 |
No.76 回数の期待値で練習
|
| コンテスト | |
| ユーザー |
kcm1700
|
| 提出日時 | 2014-11-24 00:46:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 338 ms / 5,000 ms |
| コード長 | 715 bytes |
| コンパイル時間 | 489 ms |
| コンパイル使用メモリ | 41,472 KB |
| 実行使用メモリ | 17,152 KB |
| 最終ジャッジ日時 | 2025-01-02 21:03:02 |
| 合計ジャッジ時間 | 1,246 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d",&T);
| ~~~~~^~~~~~~~~
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
ソースコード
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
double p[6] = {1./12, 2./12,3./12,1./12,3./12,2./12};
double dt[1090003][2];
int main(){
int T;
scanf("%d",&T);
while(T-->0){
int n;
scanf("%d",&n);
memset(dt,0,sizeof(dt[0]) * (n+100));
dt[0][0] = 0;
dt[0][1] = 1;
for(int i = 0; i < n; i++) {
for(int j = 1; j <= 6; j++) {
dt[i+j][0] += (dt[i][0] + dt[i][1]) * p[j-1];
dt[i+j][1] += dt[i][1]*p[j-1];
}
}
double sum = 0;
double psum = 0;
for(int i = n; i <= n+5; i++) {
sum += dt[i][0];
psum += dt[i][1];
}
printf("%.10f\n", sum/psum);
}
return 0;
}
kcm1700