Game of Connections

      Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
        Total Submission(s): 4844    Accepted Submission(s): 2811

Problem Description
This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another. And, no two segments are allowed to intersect.

It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?

 
Input
Each line of the input file will be a single positive number n, except the last line, which is a number -1. You may assume that 1 <= n <= 100.
 
Output
For each n, print in a single line the number of ways to connect the 2n numbers into pairs.
 
Sample Input
2
3
-1
 
Sample Output
2
5
 
Source
 
Recommend
Eddy   |   We have carefully selected several similar problems for you:  1133 1131 2067 1267 2018 
 
题意:
这是一个小而古老的游戏。你应该把数字1,2,3,.,2n-1,2n连续地按顺时针顺序在地上形成一个圆圈,然后画出一些直线线段,将它们连接成数对。每一个数字都必须相互联系。没有两个区段被允许相交。 这仍然是个简单的游戏,不是吗?但是,在你写下了2n的数字之后,你能告诉我,你可以用多少种不同的方式将数字连接成对?生活更艰难,对吧?
思路:
看题意,这道题是不是圆的划分?!
对,就是圆的划分,这样我们又可以用卡特兰数来做了。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 110
using namespace std;
int n,len,tmp,sum,b[N],a[N][N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int catelan()
{
    len=; a[][]=b[]=;
    ;i<;i++)
    {
        ;j<len;j++)
         a[i][j]=a[i-][j]*(i*-);
        sum=;
        ;j<len;j++)
        {
            tmp=sum+a[i][j];
            a[i][j]=tmp%;
            sum=tmp/;
        }
        while(sum)
        {
            a[i][len++]=sum%;
            sum/=;
        }
        ;j>=;j--)
        {
            tmp=sum*+a[i][j];
            a[i][j]=tmp/(i+);
            sum=tmp%(i+);
        }
        ])
         --len;
        b[i]=len;
    }
}
int main()
{
    catelan();
    )
    {
        n=read();
        ) break;
        ;i>=;i--)
         printf("%d",a[n][i]);
        printf("\n");
    }
    ;
}
 

HDU——1134 Game of Connections的更多相关文章

  1. HDU 1134 Game of Connections(卡特兰数+大数模板)

    题目代号:HDU 1134 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1134 Game of Connections Time Limit: 20 ...

  2. hdu 1134 Game of Connections

    主要考察卡特兰数,大数乘法,除法…… 链接http://acm.hdu.edu.cn/showproblem.php?pid=1134 #include<iostream>#include ...

  3. HDU - 1134 Game of Connections 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1134 题意 给出一个n 然后有2n个点 给两个点连一条边,最后连N条边,要求所有的边不能够交叉 问最多 ...

  4. HDU ACM 1134 Game of Connections / 1130 How Many Trees?(卡特兰数)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=1134 [解题背景]这题不会做,自己推公式推了一段时间,将n=3和n=4的情况列出来了,只发现第n项与 ...

  5. 【HDOJ】1134 Game of Connections

    Catlan数. /* 1134 */ import java.util.Scanner; import java.math.BigInteger; /* Catalan: (1) h(n) = h( ...

  6. HDU 1134 卡特兰数 大数乘法除法

    Problem Description This is a small but ancient game. You are supposed to write down the numbers 1, ...

  7. ACM第一阶段学习内容

    一.知识目录 字符串处理 ................................................................. 3 1.KMP 算法 .......... ...

  8. hdu 2874 Connections between cities [LCA] (lca->rmq)

    Connections between cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  9. HDU 2874 Connections between cities (LCA)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2874 题意是给你n个点,m条边(无向),q个询问.接下来m行,每行两个点一个边权,而且这个图不能有环路 ...

随机推荐

  1. C#上机作业及代码Question2

    第二题某文件名为"*.txt",其中*可能由若干个英文单词组成.将此文件名改为"*.dat",并且单词之间用下划线连接,例如: helloworld.txt,改 ...

  2. S - Cyclic Components (并查集的理解)

    Description You are given an undirected graph consisting of nn vertices and mm edges. Your task is t ...

  3. MySQL 四种事务隔离级别详解及对比--转

    http://www.jb51.net/article/100183.htm 接的隔离级别.它的语法如下: ? 1 SET [SESSION | GLOBAL] TRANSACTION ISOLATI ...

  4. Jquery 全选、反选问题的记录

    <div id="list"> <ul id="choseList" > <li><input type=" ...

  5. 13 继续C#中的方法,带返回值的方法介绍

    在这一个练习中,我们要使用带返回值的方法.如果一个方法带返回值,那么它的形式是这样的. 定义一个带返回值的C#方法 static 返回类型 方法名字 (参数类型 参数1的名字,参数类型 参数2的名字) ...

  6. FCC 基础JavaScript 练习7

    1. Math.random()用来生成一个在0(包括0)到1(不包括1)之间的随机小数,因此Math.random()可能返回0但绝不会返回1. 提示随后的函数都会在return执行前调用,所以我们 ...

  7. java继承问题

    代码: 父类: public class Father { public Father() { System.out.println("基类构造函数{"); show(); new ...

  8. 关于.Net的强名称(Strong Name)

    下面是我在CSDN上发表的<关于.Net的强名称(Strong Name)>,转载于此. 关于.Net的强名称(Strong Name)  

  9. HDU_1175_连连看

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1175 大意:连连看规则,只能转两次弯,先输入矩阵0表示没有棋子,正整数表示不同的棋子,然后询问,输入两点坐 ...

  10. lsb_release No LSB modules are available

    lsb_release 提示: No LSB modules are available   执行: sudo apt-get install lsb-core