結果

問題 No.108 トリプルカードコンプ
ユーザー syoken_desukasyoken_desuka
提出日時 2015-03-05 05:53:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 5,222 bytes
コンパイル時間 4,575 ms
コンパイル使用メモリ 111,608 KB
実行使用メモリ 31,056 KB
最終ジャッジ日時 2024-06-24 08:02:03
合計ジャッジ時間 2,581 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,008 KB
testcase_01 AC 30 ms
24,880 KB
testcase_02 AC 27 ms
24,184 KB
testcase_03 AC 28 ms
26,952 KB
testcase_04 AC 29 ms
24,636 KB
testcase_05 AC 27 ms
23,808 KB
testcase_06 AC 27 ms
23,988 KB
testcase_07 AC 47 ms
26,420 KB
testcase_08 AC 42 ms
31,056 KB
testcase_09 AC 42 ms
28,508 KB
testcase_10 AC 42 ms
27,776 KB
testcase_11 AC 41 ms
29,108 KB
testcase_12 AC 28 ms
22,964 KB
testcase_13 AC 29 ms
25,008 KB
testcase_14 AC 29 ms
26,960 KB
testcase_15 AC 29 ms
24,748 KB
testcase_16 AC 31 ms
27,048 KB
testcase_17 AC 29 ms
24,748 KB
testcase_18 AC 43 ms
30,768 KB
testcase_19 AC 40 ms
29,944 KB
testcase_20 AC 43 ms
28,284 KB
testcase_21 AC 45 ms
29,212 KB
testcase_22 AC 44 ms
27,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

#region ZIPPER
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Numerics;
using sc = Scanner;
class Program
{
    static void Main(string[] args)
    {
        Solver solver = new Solver();
        solver.Solve();
#if DEBUG
        System.Console.WriteLine("続行するには何かキーを押してください...");
        System.Console.ReadKey();
#endif

    }
}
/// <summary>
/// Java風のスキャナー,自作(某最速の人を参考)
/// </summary>
public static class Scanner
{
    public static string NextString()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return tmp;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return int.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return long.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return double.Parse(tmp);
    }

    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static double[] NextDoubleArray()
    {
        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}
#endregion ZIPPER

public class Solver
{
#region IGNORE_ME
    public Solver()
    {
        //こんすとらくたん きにしなくてよろしい
    }
#endregion IGNORE_ME

#region FIELD

#endregion FIELD

    public void Solve()
    {
        int n = sc.NextInt();
        double[, ,] dp = new double[ n + 1,  n + 1,  n + 1];// ima 0, ima 1, ima 2;
        int[] start = new int[4];
        int[] a = sc.NextIntArray();
        for (int i = 0; i < n; i++)
        {
            a[i] = a[i] > 3 ? 3 : a[i];
            start[a[i]]++;
        }
        for (int i = 0; i < n+1; i++)
        {
            for (int j = 0; j < n+1; j++)
            {
                for (int k = 0; k < n + 1; k++)
                {

                    if ((i + j + k > n) || (i + j + k == 0))
                    {
                        continue;
                    }
                    double noneGet = 1.0 * i / n;
                    double oneGet = 1.0 * j / n;
                    double twoGet = 1.0 * k / n;
                    double daburi = 1.0 * (n - i - j - k) / n;
                    double daburiKeisu = daburi == 0 ? 1 : (1 / (1 - daburi));
                    dp[i, j, k] = daburiKeisu
                        * (noneGet * dp[Math.Max(i - 1, 0), Math.Min(j + 1, n), k]
                          + oneGet * dp[i, Math.Max(j - 1, 0), Math.Min(k + 1, n)]
                          + twoGet * dp[i, j, Math.Max(k - 1, 0)]
                          + 1);


#if DEBUG
                    Console.WriteLine("{0} {1} {2}", i, j, k);
                    Console.WriteLine("{0} {1} {2}: {3}", noneGet, oneGet, twoGet, dp[i, j, k]);
#endif
                }
            } 
        }
        Console.WriteLine(dp[start[0], start[1], start[2]]);
#if DEBUG
        Console.WriteLine("");//local check
#endif
    }

}
0