Buy the Ticket

Source: Internet
Author: User

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4981 Accepted Submission (s): 2085


Problem DescriptionThe "Harry Potter and the Goblet of Fire" would be on show in the next few days. As a crazy fan of Harry Potter, you'll go to the cinema and has the first sight, won ' t you?

Suppose the cinema only have one ticket-office and the price for per-ticket are dollars. The queue for buying the tickets are consisted of M + N persons (m persons each have the 50-dollar bill and N persons E Ach only has the 100-dollar bill).

Now, the problem for are to calculate the number of different ways of the "the" and the buying process won ' t be stopped From the first person till the last person.
Note:initially the Ticket-office has no money.

The buying process is stopped on the occasion that the Ticket-office have no 50-dollar bill but the first person of th E queue only had the 100-dollar bill.

Inputthe input file contains several test cases. Each test case was made up of Numbers:m and N. It is terminated by M = n = 0. Otherwise, M, N <=100.

Outputfor each test case, first print the test number (counting from 1) and then output the number of different W Ays in another line.

Sample Input3 03 13 30 0

Sample outputtest #1:6Test #2:18Test #3:180

Author
#include <cstdio> #include <cstring>int a[390];int n,m,leap;void bfact (int n) {int i,j;        for (i=2; i<=n; i++) {if (leap&&i==m+1) continue;        int c=0,s;            for (j=0; j<380; J + +) {s=i*a[j]+c;            a[j]=s%10;        C=S/10;    }}}void bx (int n) {int J;    int s,c=0;        for (j=0; j<380; J + +) {s=n*a[j]+c;        a[j]=s%10;    C=S/10;    }}int Main () {//freopen ("case.in", "R", stdin);    int i,j,c=1;        while (scanf ("%d%d", &m,&n)!=-1) {if (!m&&!n) break;        Leap=0;        memset (A,0,sizeof (a));        A[0]=1;        printf ("Test #%d:\n", c);            if (m<n) {printf ("0\n");            C + +;        Continue        } if ((m-n+1)% (m+1) ==0) bx ((m-n+1)/(m+1));            else {bx (m-n+1);        Leap=1;        } bfact (N+m);        for (i=380; i>=0; i--) if (a[i]) break; for (j=i; j>= 0;        j--) printf ("%d", a[j]);        printf ("\ n");    C + +; }}//found the formula on the Internet: The result is equal to (m+n)!* (m-n+1)/(m+1)//Then the problem is high precision

  

Buy the Ticket

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.