結果
| 問題 | No.76 回数の期待値で練習 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-15 21:46:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 5,000 ms |
| コード長 | 1,267 bytes |
| コンパイル時間 | 640 ms |
| コンパイル使用メモリ | 63,744 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 06:13:45 |
| 合計ジャッジ時間 | 1,098 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
ソースコード
#include <cstdio>
#include <vector>
#include <array>
#include <map>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
int main() {
// input
int q; scanf("%d", &q);
map<int,vector<int> > f;
repeat (i,q) {
int n; scanf("%d", &n);
f[n].push_back(i);
}
// compute
vector<double> ans(q);
array<long double,7> e = { 0, 1.0000000000000000, 1.0833333333333333, 1.2569444444444444, 1.5353009259259260, 1.6915991512345676, 2.0513639724794235 };
array<long double,6> p = {};
p[0] = e[2] - 1;
p[1] = e[3] - p[0]*e[2] - 1;
p[2] = e[4] - p[0]*e[3] - p[1]*e[2] - 1;
p[3] = e[5] - p[0]*e[4] - p[1]*e[3] - p[2]*e[2] - 1;
p[4] = e[6] - p[0]*e[5] - p[1]*e[4] - p[2]*e[3] - p[3]*e[2] - 1;
p[5] = 1 - p[0] - p[1] - p[2] - p[3] - p[4];
int limit = f.rbegin()->first + 1;
repeat (i,limit) {
if (i > 6) {
e[i%7] = 1;
repeat (j,6) {
e[i%7] += p[j] * e[(i-j-1 +7)%7];
}
}
if (f.count(i)) for (int j : f[i]) {
ans[j] = e[i%7];
}
}
// output
repeat (i,q) {
printf("%.16lf\n", ans[i]);
}
return 0;
}