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
  • 相关阅读:
    程序员修炼之道——从小工到专家 读书笔记
    Spring5 IOC原理
    2021下期末总结
    十年风雨,一个普通程序员的成长之路(五) 成长:得到与教训
    UmbracoXslDevelopmentTemplate CQ
    Asp.net中的数据绑定 CQ
    Building the DotNetNuke Module in Normal Asp.net Application CQ
    UmbracoDataTypeFirstGlance CQ
    Umbraco Home CQ
    UmbracoColor Picker–Demo CQ
  • 原文地址:https://www.cnblogs.com/dulute/p/7272372.html
Copyright © 2011-2022 走看看