結果

問題 No.352 カード並べ
ユーザー nanophoto12nanophoto12
提出日時 2016-03-12 10:34:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 69,584 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 08:00:44
合計ジャッジ時間 1,220 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;

#define REP(i,x) for(int i=0;i<(int)(x);i++)

int n;

ll perm(int i)
{
    ll r = 1;
    while(i > 0)
    {
        r *= i;
        i--;
    }
    return r;
}

int main(){
    cin >> n;
    double ex = 0;
    
    if(n == 2)
    {
        cout << 2 << endl;
        return 0;
    }
    ex = 2;
    for(int i = 3;i <= n;i++)
    {
        double s = 2.0;
        double pe = perm(i-2) / (double)perm(i - 1);
        for(int l = 1;l < i;l++)
        {
            for(int r = 1;r < i;r++)
            {
                if(l == r)
                {
                    continue;
                }
                double d = (l * r);
                s += d * pe;
            }
        }
        s /= i;
        ex += s;
    }
    cout << setprecision(8);
    cout << fixed;
    cout << ex << endl;
    return 0;
}
0