zoukankan      html  css  js  c++  java
  • Game of Connections

    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? 

    InputEach 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. 
    OutputFor 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

    卡兰特数套公式
    java大法好啊!
     1 import java.util.*;
     2 import java.math.*;
     3 public class Main 
     4 {
     5  public static BigInteger TM;
     6  public static void main(String[] args)
     7  {
     8   Scanner sc=new Scanner(System.in);
     9   while(sc.hasNext())
    10   {
    11    int n=sc.nextInt();
    12    if(n==-1)
    13        break;
    14    int a,b;
    15    TM=BigInteger.ONE;
    16    TM=TM.multiply(BigInteger.valueOf(2));
    17    if(n==1)
    18    {
    19        System.out.println(1);
    20        continue;
    21    }
    22    if(n==2)
    23    {
    24        System.out.println(2);
    25        continue;
    26    }
    27    for(int i=3;i<=n;i++)
    28    {
    29        a=4*i-2;
    30        b=i+1;
    31     TM=TM.multiply(BigInteger.valueOf(a));
    32     TM=TM.divide(BigInteger.valueOf(b));
    33    
    34    }
    35    System.out.println(TM);
    36   }
    37  }
    38 }
    View Code
  • 相关阅读:
    发张照片纪念下
    以用户为中心的SNS站点数据库设计及实现
    IT点评:腾讯帝国没落的开始从崇敬到平淡,改变从自己开始
    并发下常见的加锁及锁的PHP具体实现
    Ubuntu,Your Linux
    Python初尝试
    C++ Primer Plus读书笔记02
    C++ Primer Plus读书笔记03
    Effective C++读书笔记02
    由扔骰子看平均概率生成
  • 原文地址:https://www.cnblogs.com/dulute/p/7272372.html
Copyright © 2011-2022 走看看