結果
| 問題 |
No.58 イカサマなサイコロ
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-08-03 21:39:10 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 5,000 ms |
| コード長 | 2,818 bytes |
| コンパイル時間 | 1,808 ms |
| コンパイル使用メモリ | 109,292 KB |
| 実行使用メモリ | 27,456 KB |
| 最終ジャッジ日時 | 2024-07-18 01:09:34 |
| 合計ジャッジ時間 | 2,551 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
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 Program
{
static string InputPattern = "Input3";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("2");
WillReturn.Add("1");
//出力
//0.62191
//太郎君は普通のサイコロとイカサマなサイコロを1個づつ使用し、
//二郎君は普通のサイコロを2個使用します
}
else if (InputPattern == "Input2") {
WillReturn.Add("10");
WillReturn.Add("0");
//出力
//0.47409
//太郎君はイカサマなサイコロを使わず、公平に勝負しました
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int N = int.Parse(InputList[0]);
int K = int.Parse(InputList[1]);
Dictionary<int, int> CntDict1 = DeriveCntDict(N, K);
Dictionary<int, int> CntDict2 = DeriveCntDict(N, 0);
//積の法則で分母を求める
Decimal Bunbo = (Decimal)CntDict1.Values.Sum()
* (Decimal)CntDict2.Values.Sum();
//積の法則で分子を求める
Decimal Bunsi = 0;
foreach (var EachPair1 in CntDict1) {
foreach (var EachPair2 in CntDict2) {
if (EachPair1.Key <= EachPair2.Key)
continue;
Bunsi += (Decimal)EachPair1.Value
* (Decimal)EachPair2.Value;
}
}
Console.WriteLine(Bunsi / Bunbo);
}
//合計ごとの場合の数を動的計画法で求める
static Dictionary<int, int> DeriveCntDict(int pN, int pK)
{
var CntDict = new Dictionary<int, int>();
CntDict[0] = 1; //初期設定
for (int I = 1; I <= pN; I++) {
var NewCntDict = new Dictionary<int, int>();
int[] DiceValsArr = { 1, 2, 3, 4, 5, 6 };
//456サイの場合
if (I <= pK)
DiceValsArr = new int[] { 4, 5, 6, 4, 5, 6 };
foreach (int EachDiceVal in DiceValsArr) {
foreach (var EachPair in CntDict) {
int NewKey = EachPair.Key + EachDiceVal;
if (NewCntDict.ContainsKey(NewKey)) {
NewCntDict[NewKey] += EachPair.Value;
}
else NewCntDict[NewKey] = EachPair.Value;
}
}
CntDict = NewCntDict;
}
return CntDict;
}
}
明智重蔵