結果
| 問題 | No.76 回数の期待値で練習 |
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-12-11 20:39:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 486 ms / 5,000 ms |
| コード長 | 1,777 bytes |
| コンパイル時間 | 488 ms |
| コンパイル使用メモリ | 41,320 KB |
| 実行使用メモリ | 9,404 KB |
| 最終ジャッジ日時 | 2024-06-11 20:37:37 |
| 合計ジャッジ時間 | 1,058 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d", &T);
| ~~~~~^~~~~~~~~~
main.cpp:57:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
#include <cmath>
int T;
double sample[7] = {
0.0,
1.0000000000000000,
1.0833333333333333,
1.2569444444444444,
1.5353009259259260,
1.6915991512345676,
2.0513639724794235
}, probability[7], dp[1000001];;
int main(){
{
double e[7], sum;
for(int i=1;i<=5;i++){
std::fill(e, e+7, 0.0);
for(int j=i;j>0;j--){
sum = 0.0;
for(int k=1;k<=6;k++){
if(j+k >= i+1){e[j] += (1.0-sum) * 1; break;}
e[j] += probability[k] * (e[j+k] + 1);
sum += probability[k];
}
// printf("%d, %d: %f\n", i, j, e[j]);
}
double x = 0.0, y = 0.0;
for(int j=1;j<=6;j++){
if(j >= i+1){x += (1-sum) * 1; y -= 1.0; break;}
if(j == i){y += e[j] + 1;}
else{x += probability[j] * (e[j] + 1);}
}
// printf("%d: x=%f, y=%f\n", i, x, y);
probability[i] = (sample[i+1] - x) / y;
sum += probability[i];
}
probability[6] = 1.0;
for(int i=1;i<=5;i++){
probability[6] -= probability[i];
}
// for(int i=1;i<=6;i++){
// printf("%f\n", probability[i]);
// }
}
scanf("%d", &T);
for(int _=0;_<T;_++){
int n;
scanf("%d", &n);
std::fill(dp, dp+n+1, 0.0);
for(int i=1;i<=n;i++){
for(int j=1;j<=6;j++){
dp[i] += probability[j] * (dp[std::max(i-j,0)] + 1);
}
}
printf("%.10f\n", dp[n]);
}
}
tottoripaper