HDOJ 1133 Buy the tickets!

来源:互联网 发布:前台ajax获取json数据 编辑:程序博客网 时间:2024/06/14 07:41
Problem Description
The "Harry Potter and the Goblet of Fire" will be on show in the next few days. As a crazy fan of Harry Potter, you will go to the cinema and have the first sight, won’t you?

Suppose the cinema only has one ticket-office and the price for per-ticket is 50 dollars. The queue for buying the tickets is consisted of m + n persons (m persons each only has the 50-dollar bill and n persons each only has the 100-dollar bill).

Now the problem for you is to calculate the number of different ways of the queue that 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 will be stopped on the occasion that the ticket-office has no 50-dollar bill but the first person of the queue only has the 100-dollar bill.
 

Input
The input file contains several test cases. Each test case is made up of two integer numbers: m and n. It is terminated by m = n = 0. Otherwise, m, n <=100.
 

Output
For each test case, first print the test number (counting from 1) in one line, then output the number of different ways in another line.
 

Sample Input
3 03 13 30 0
 

Sample Output
Test #1:6Test #2:18Test #3:180
////  main.cpp//  1133////  Created by 张嘉韬 on 16/2/2.//  Copyright © 2016年 张嘉韬. All rights reserved.//#include <iostream>#include <cmath>#include <cstring>using namespace std;const int maxn=390;int main(){    int m,n,f[maxn],temp,c,len,a,t;    t=0;    while(scanf("%d%d",&m,&n)==2&&(m||n))    { t++;        if(n>m)        {            cout<<"Test #"<<t<<":"<<endl;            cout<<0<<endl;            continue;        }      memset(f,0,sizeof(f));    f[1]=1;    for(int i=2;i<=m+n;i++)    {        c=0;        for(int j=1;j<=maxn-1;j++)        {            temp=f[j]*i+c;            f[j]=temp%10;            c=temp/10;        }    }    c=0;    a=m-n+1;    for(int j=1;j<=maxn-1;j++)    {        temp=f[j]*a+c;        f[j]=temp%10;        c=temp/10;    }    c=0;    a=m+1;    len=maxn-1;    while(f[len]==0) len--;    for(int i=len;i>=1;i--)    {        temp=c+f[i];        f[i]=temp/a;        c=(temp%a)*10;    }        cout<<"Test #"<<t<<":"<<endl;    len=maxn-1;    while(f[len]==0) len--;    for(int i=len;i>=1;i--) cout<<f[i];    cout<<endl;  }    return 0;}

总结
该题应用的思路和特别,首先整体上使用了排除法的思路,将不合法的除去剩下的就是合法的了,具体的解析见点击打开链接,在该题中我们还练习了大数/小数且结果是正数的高精度除法
0 0
原创粉丝点击