SGU130 Circle

SGU130 Circle

题目大意

将圆周上的2K个点两两连接,将圆分割为最少数量的弧
问连接方案数与最少的数量分别为多少

算法思路

不难发现,连接出来的K条弦在不相交的情况下,把圆分解为K+1条圆弧,是数量最少的方案
而方案数则是卡特兰数的经典实例,资料很多这里就不多做解释了

时间复杂度: O(K)

代码

/** * Copyright © 2015 Authors. All rights reserved. * * FileName: 130.cpp * Author: Beiyu Li <[email protected]> * Date: 2015-06-13 */
#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
        int k;
        scanf("%d", &k);
        LL c = 1;
        For(i,1,k) c = c * (4 * i - 2) / (i + 1);
        printf("%I64d %d\n", c, k + 1);

        return 0;
}

你可能感兴趣的:(组合数学,sgu)