[Stack] Shooting Game (to be updated)

Source: Internet
Author: User

Description

James enjoys shooting games. This weekend, after finishing his data structure jobs, he came to the shooting casino again. He rented a rifle from his boss and a magazine containing N bullets. Note: All bullets are loaded from the muzzle. During the shooting process, James had two options each time: getting a bullet from the clip and loading it, or hitting a bullet. Coincidentally, this Tuesday, Xiao Minggang took the chapter stack in the data structure, so, he wants to use the "stack" Data Structure to figure out how many different bullet strike sequences there are. Assume that N bullets are numbered 1, 2 ,..., N. The order of the bullets taken from the cartridge is also from 1 to n. Can you help James solve this problem?

Input

There may be multiple test inputs. The first line shows the total number of test inputs.

Each test input has only one integer n.

Output

Output an integer, that is, the total number of all different sequences.

Sample Input

Copy sample input to clipboard

13

Sample output

5

Problem Source: course exercise questions

Solution:

Method 1: formula 2n! /(N + 1) n! N !)

#include<iostream>using std::cout;using std::cin;using std::endl;int main() {    long long int T, n, tmp1, tmp2, i;    cin >> T;    for (; T > 0; T--) {        cin >> n;        for (i = 2 * n, tmp1 = 1; i >= (n + 2); i--) tmp1 *= i;        for (i = n, tmp2 = 1; i >= 1; i--) tmp2 *= i;        cout << (tmp1 / tmp2) << endl;    }}                  

  

Method 2: to be updated

 

 

(I have referenced other online materials more or less in this blog, but I have forgotten my reference for a long time. I would like to thank them !)

 

[Stack] Shooting Game (to be updated)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.