はまやんはまやんはまやん

hamayanhamayan's blog

休日の平均 [yukicoder 926]

https://yukicoder.me/problems/no/926

解説

https://yukicoder.me/submissions/399496

最後の「一週間の内の休日の位置が変わった場合でも平均の休日数は変わらないことが証明できます。」が
あるおかげで簡単に解けそうだ。
一週間の先頭C日間が休日として問題なさそう。
平均を取る必要があり、パターンを考える。
一年の最初の日が、一週間の何日目かを考えれば良さそう。

int A, B, C;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B >> C;

    int tot = 0;
    rep(top, 0, B) {
        rep(d, 0, A) {
            int td = (top + d) % B;
            if (td < C) tot++;
        }
    }
    double ans = 1.0 * tot / B;
    printf("%.8f\n", ans);
}