Home » Java » Zhongkai ACM 1095: train station [Java]

Zhongkai ACM 1095: train station [Java]

Title Description


Railway train dispatching, the platform designed to stack structure of the platform, ask:

A numbered 1 to n n train, the order into the stack structure of the platform, may the stack sequence number >


Input format


The input contains multiple sets of test data. Each group is a positive integer n (1<=n<=20) indicating the N train.


output


How many.

sequences are possible for the output stack?
sample input


4

3


sample output


14


5


by Baidu, get the formula (2*n) / (n * n!!! * (n + 1)) (n>=1). Calculation of n to 2n and n. The factorial factorial, because 0 to order 2n to n factorial and =n to 2n factorial.


n=20,20 to number 40, if the factorial is still great, that the long are not wide enough, but you must use the double. double is a floating-point value, the topic request output is the integer value. Similar to the 1010 grade point average, using the java.text.DecimalFormat package to solve.


import java.text.DecimalFormat;


DecimalFormat DF = new DecimalFormat ("0");


System.out.println (df.format (sum));


package acm;
Import java.util.Scanner;
Import java.text.DecimalFormat;
Public class train leaving station {
Public, static, void, main (String[]args)
{
Scanner input = new Scanner (System.in);
DecimalFormat DF = new DecimalFormat ("0");
While (input.hasNextInt ()) {
Int a = input.nextInt ();
If (a > = 0 & & a <=20) {
Double sum = 0;
Double C = 1;
For (int b = a; B < 2*a; B + +) {
C = C * (B + 1); / / A to 2A factorial calculation
}
Double E = 1;
For (int d = 0; d < A; D + +) {
E = e * (D + 1); / / a factorial calculation
}
Sum = C / (e* (a + 1));
System.out.println (df.format (sum));
}
}
}
}




Latest