結果

問題 No.76 回数の期待値で練習
ユーザー nanophoto12nanophoto12
提出日時 2014-11-26 01:38:11
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,236 bytes
コンパイル時間 2,511 ms
コンパイル使用メモリ 103,828 KB
実行使用メモリ 25,636 KB
最終ジャッジ日時 2023-09-01 22:08:58
合計ジャッジ時間 3,189 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
25,636 KB
testcase_01 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;

class Program76
{
    private static double calculate(double[] expectations, double[] percentange, int lowerValue)
    {
        double sum = 1;
        int first = Math.Max(lowerValue - 6, 0);
        for (int sourceIndex = first; sourceIndex <= lowerValue - 1; sourceIndex++)
        {
            for (int p = 1; p <= 6; p++)
            {
                if (sourceIndex + p == lowerValue)
                {
                    sum += percentange[p] * expectations[sourceIndex];
                }
            }
        }
        return sum;
    }


    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        List<int> values = new List<int>();
        for (int i = 0; i < n; i++)
        {
            values.Add(int.Parse(Console.ReadLine()));
        }
        double[] expected = new double[1010000];
        expected[1] = 1;
        expected[2] = 1.0833333333333333;
        expected[3] = 1.2569444444444444;
        expected[4] = 1.5353009259259260;
        expected[5] = 1.6915991512345676;
        expected[6] = 2.0513639724794235;

        double[] dicePercentage = new double[7];
        expected[1] = 1;
        for (int j = 1; j <= 5; j++)
        {
            double lower = 0;
            double upper = 1;
            for (int i = 0; i < 70; i++)
            {
                double mid = lower + upper;
                mid /= 2d;
                dicePercentage[j] = mid;
                int lowerValue = j + 1;
                var result = calculate(expected, dicePercentage, lowerValue);
                if (result < expected[j + 1])
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }
            }
        }
        dicePercentage[6] = 1 - dicePercentage.Sum();
        for (int i = 7; i <= 100001; i++)
        {
            expected[i] = calculate(expected, dicePercentage, i);
        }
        foreach (var element in values)
        {
            Console.WriteLine(expected[element]);            
        }
    }
}
0