結果

問題 No.76 回数の期待値で練習
ユーザー mbanmban
提出日時 2017-07-21 13:23:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 1,711 bytes
コンパイル時間 3,687 ms
コンパイル使用メモリ 104,292 KB
実行使用メモリ 31,868 KB
最終ジャッジ日時 2023-07-30 08:45:54
合計ジャッジ時間 3,104 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
31,868 KB
testcase_01 AC 99 ms
29,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

struct S
{
    public bool[] Use;
    public long Price;
    public S(long p, bool[] u)
    {
        Price = p;
        Use = u;
    }
}

class Magatro
{
    private double[] D = new double[7] { 0, 1.0000000000000000, 1.0833333333333333, 1.2569444444444444, 1.5353009259259260, 1.6915991512345676, 2.0513639724794235 };
    private double[] X = new double[7];
    private double[] Ans = new double[1000001];

    private void Scan()
    {

    }

    private void Calc()
    {
        X[1] = D[2] - 1;
        X[2] = D[3] - X[1] * D[2] - 1;
        X[3] = D[4] - X[1] * D[3] - X[2] * D[2] - 1;
        X[4] = D[5] - X[1] * D[4] - X[2] * D[3] - X[3] * D[2] - 1;
        X[5] = D[6] - X[1] * D[5] - X[2] * D[4] - X[3] * D[3] - X[4] * D[2] - 1;
        X[6] = 1 - X[1] - X[2] - X[3] - X[4] - X[5];
        for (int i = 0; i <= 6; i++)
        {
            Ans[i] = D[i];
        }
        for (int i = 7; i <= 1000000; i++)
        {
            for (int j = 1; j <= 6; j++)
            {
                Ans[i] += Ans[i - j] * X[j];
            }
            Ans[i]++;
        }
    }


    public void Solve()
    {
        Scan();
        Calc();
        StringBuilder sb = new StringBuilder();
        int T = int.Parse(Console.ReadLine());
        for (int i = 0; i < T; i++)
        {
            sb.AppendLine(Ans[int.Parse(Console.ReadLine())].ToString());
        }
        Console.Write(sb.ToString());
    }
}
0