結果
| 問題 | No.76 回数の期待値で練習 |
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2014-11-26 01:39:32 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 122 ms / 5,000 ms |
| コード長 | 2,237 bytes |
| コンパイル時間 | 2,264 ms |
| コンパイル使用メモリ | 108,032 KB |
| 実行使用メモリ | 27,264 KB |
| 最終ジャッジ日時 | 2025-01-03 08:51:59 |
| 合計ジャッジ時間 | 3,074 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 <= 1000001; i++)
{
expected[i] = calculate(expected, dicePercentage, i);
}
foreach (var element in values)
{
Console.WriteLine(expected[element]);
}
}
}
nanophoto12