結果

問題 No.352 カード並べ
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-04-06 16:09:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 61,184 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-27 09:38:05
合計ジャッジ時間 1,688 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<vector>

using namespace std;

#define N 20

int main(){

	long long num_data[N + 1];
	long long one_data[N + 1];
	long long n;
	double ans_data[N + 1];
	vector<long long> vnum;

	num_data[1] = 1;
	n = 2;
	for (long long i = 2; i <= N; i++) num_data[i] = n, n *= i + 1;

	one_data[1] = 1;
	for (long long i = 2; i <= N; i++) one_data[i] = num_data[i - 1] * 2;

	ans_data[1] = 1.0;
	ans_data[2] = 2.0;
	long long w = 2;

	cin >> n;

	for (long long i = 3; i <= n; i++){
		for (long long j = 1; j < i - 1; j++){
			vnum.push_back((i - 1)*j);
		}
		ans_data[i] = one_data[i];
		long long c = (num_data[i] - one_data[i]) / vnum.size();

		for (long long j = 0; j < vnum.size(); j++){
			ans_data[i] += vnum[j]*c;
		}
		
		w *= i;
		ans_data[i] /= w;
		ans_data[i] += ans_data[i - 1];
	}

	printf("%.12f\n", ans_data[n]);
}
0