結果

問題 No.75 回数の期待値の問題
ユーザー syoken_desukasyoken_desuka
提出日時 2015-03-01 14:42:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 4,852 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 105,668 KB
実行使用メモリ 24,700 KB
最終ジャッジ日時 2023-09-06 05:51:00
合計ジャッジ時間 4,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
20,540 KB
testcase_01 AC 51 ms
20,592 KB
testcase_02 AC 51 ms
20,636 KB
testcase_03 AC 57 ms
24,584 KB
testcase_04 AC 48 ms
20,752 KB
testcase_05 AC 53 ms
22,896 KB
testcase_06 AC 50 ms
20,644 KB
testcase_07 AC 57 ms
22,572 KB
testcase_08 AC 58 ms
22,724 KB
testcase_09 AC 56 ms
22,728 KB
testcase_10 AC 57 ms
22,632 KB
testcase_11 AC 57 ms
24,700 KB
testcase_12 AC 56 ms
22,624 KB
testcase_13 AC 58 ms
24,584 KB
testcase_14 AC 56 ms
22,576 KB
testcase_15 AC 54 ms
22,580 KB
testcase_16 AC 54 ms
22,620 KB
testcase_17 AC 62 ms
24,656 KB
testcase_18 AC 71 ms
22,580 KB
testcase_19 AC 74 ms
24,636 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.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Numerics;
using sc = Scanner;

class Program
{
    static void Main(string[] args)
    {
        Solve();
#if DEBUG
        System.Console.WriteLine("続行するには何かキーを押してください...");
        System.Console.ReadKey();
#endif

    }

    /// <summary>
    /// ここでとく
    /// </summary>
    static void Solve()
    {
        int n = sc.NextInt();
        double[,] mat = new double[n,n+1];
        if (n >= 0 && n < 7)
        {
            Console.WriteLine(6);
            return;
        }
        for (int i = 0; i < n; i++)
        {
            mat[i, i] = 6.0;
            mat[i, n] = 6.0;
        }
        for (int i = 0; i < 6; i++)
        {
            mat[(n - 1) - i, 0] = -6.0 + 1.0 * (i + 1);
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < i+7 && j < n; j++)
            {
                mat[i, j] = -1.0;
            }
        }
#if DEBUG
        Console.WriteLine("mat check");
#endif 

        for (int i = 0; i < n; i++)
        {
            double d = mat[i,i];
            for (int j = i; j < n+1; j++)
            {
                mat[i, j] /= d; // i retu wo seiki ka
            }
            for (int j = i+1; j < n; j++)
            {
                for (int k = i+1; k < n+1; k++)
                {
                    mat[j, k] -= mat[j, i] * mat[i, k];
                }
                mat[j, i] = 0;
            }
#if DEBUG
                Console.WriteLine("kkk");
#endif 

            
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < i; j++)
            {
#if DEBUG
                Console.WriteLine("{0} {1}: {2} {3}",n-1-i,n-1-j,n-1-j,n);
#endif 
                mat[n-1-i,n] -= mat[n-1-i,n-1-j]*mat[n-1-j,n];
                mat[n-1-i, n - 1 - j] = 0;
            }
        }


        Console.WriteLine(mat[0, n]);
#if DEBUG
        Console.WriteLine("local check"); // Visual Studioのローカル変数チェック用 MainにいくとSolve内のローカル変数消えちゃう
#endif 

    }

    
}

/// <summary>
/// Java風のスキャナー,自作(某最速の人を参考) 自分の実装のせいか,バグってるっぽい バグが出たらO(n^3) n=100000 でTLE
/// </summary>
public static class Scanner
{
    public static string NextString()
    {
        string tmp = "";
        while (true)
        {
            int readData = Console.Read();
                if (readData == -1)
                {
                   break;
                }
            string data = char.ConvertFromUtf32(Console.Read());
            if (data == " " || data == "\n")
                break;
            tmp += readData;
        }
        return tmp;
    }

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

    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 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 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 double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return double.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return long.Parse(tmp);
    }
    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;
    }
}

0