Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4981    Accepted Submission(s): 2085

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 0
3 1
3 3
0 0
 
Sample Output
Test #1:
6
Test #2:
18
Test #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++;
}
}
//从网上找到了公式 即:结果等于 (m+n)!*(m-n+1)/(m+1)
//那么这题就是高精度问题了

  

Buy the Ticket的更多相关文章

  1. Buy the Ticket{HDU1133}

    Buy the TicketTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. 【HDU 1133】 Buy the Ticket (卡特兰数)

    Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...

  3. 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. Buy the Ticket(卡特兰数+递推高精度)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. hdu 1133 Buy the Ticket(Catalan)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  6. Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)

    题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...

  7. HDUOJ---1133(卡特兰数扩展)Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. Codeforces 938.D Buy a Ticket

    D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. hdu 1133 Buy the Ticket (大数+递推)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  10. Codeforces 938D Buy a Ticket (转化建图 + 最短路)

    题目链接  Buy a Ticket 题意   给定一个无向图.对于每个$i$ $\in$ $[1, n]$, 求$min\left\{2d(i,j) + a_{j}\right\}$ 建立超级源点$ ...

随机推荐

  1. zhx and contest (枚举  + dfs)

    zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. 初识suse-Linux相关!

    Linux这种系统很奇怪,差不多每种不同的版本,它所使用的安装等一些重要命令皆有所变化.假若,你要熟练掌握一种OS,那么如果安装软件/应用,那是入门的第一步. 安装命令中: RedHat.CentOS ...

  3. NGUI无限滑动

    http://www.unity蛮牛.com/blog-9383-1391.html 最近由于工作需要,就开始研究NGUI滑动.刚开始参考NGUI自带的循环滑动,利用隐藏和显示,提高GPU的渲染,但是 ...

  4. ZeroMQ(java)之I/O线程的实现与组件间的通信

    算是开始读ZeroMQ(java)的代码实现了吧,现在有了一个大体的了解,看起来实现是比较的干净的,抽象什么的不算复杂... 这里先来看看它的I/O线程的实现吧,顺带看看是如何实现组件的通信的.... ...

  5. FOJ 1205

    Problem 1205 小鼠迷宫问题 Accept: 522    Submit: 1679 Time Limit: 1000 mSec    Memory Limit : 32768 KB Pro ...

  6. 学习jquery mobile

    学习jquery mobile的时间不是很长,在学习的过程当中也遇到了很多令人抓狂的问题,在网上搜索问题答案的时候发现,现在关于jquery mobile的文章还不是很多,所以,我也是一边学习,一边摸 ...

  7. hdparm测试硬盘性能

    <1>Centos安装hdparm测试硬盘性能 一.安装hdparm yum install hdparm -y Linux学习,http:// linux.it.net.cn 二.评估读 ...

  8. 【系统】CentOS、Ubuntu、Debian三个linux比较异同

    CentOS.Ubuntu.Debian三个linux比较异同 2014-07-31 12:58             53428人阅读             评论(6)             ...

  9. 编译安装0bda 8179无线网卡

    CentOS下安装USB无线网卡(Obda:8179) 参考:http://blog.163.com/thinki_cao/blog/static/83944875201311593529913/ c ...

  10. c++关键字之#define typedef const

    [#define] #define是预处理指令,在编译预处理时进行简单的替换,不作正确性检查. [typedef] typedef只是为了增加可读性而为标识符另起的新名称 在自己的作用域内给一个已经存 ...