結果

問題 No.352 カード並べ
ユーザー ぴろずぴろず
提出日時 2016-04-15 15:56:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 74,744 KB
実行使用メモリ 54,424 KB
最終ジャッジ日時 2024-04-15 01:46:07
合計ジャッジ時間 3,967 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
54,424 KB
testcase_01 AC 130 ms
54,160 KB
testcase_02 AC 129 ms
54,152 KB
testcase_03 AC 116 ms
53,424 KB
testcase_04 AC 129 ms
54,096 KB
testcase_05 AC 132 ms
54,120 KB
testcase_06 AC 116 ms
53,084 KB
testcase_07 AC 133 ms
54,076 KB
testcase_08 AC 129 ms
54,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no352;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.printf("%.7f\n",solve(n));
	}

	public static double solve(int n) {
		double[] fact = new double[n+1];
		fact[0] = 1;
		for(int i=1;i<=n;i++) {
			fact[i] = fact[i-1] * i;
		}
		double sum = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				int m = n - Math.max(i,j);
				double pattern = 0;
				for(int k=1;k<=m;k++) {
					pattern += fact[m] / fact[m-k] * fact[n-k-1] * 2;
				}
				sum += pattern * (i * j - 1) / fact[n];
			}
		}
		sum += n;
		return sum;
	}

}
0