Buy the Ticket

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5566    Accepted Submission(s): 2326

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
 

#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

#define base 10000

int a[101];

void multiply(int x)

{

    a[100]=1;

    for(int i=1;i<=x;i++)

       for(int j=100,temp=0;j>=0;j--)

       {

            temp+=a[j]*i;

            a[j]=temp%base;

            temp=temp/base;

       }

}

void chen(int x)

{

    int temp=0;

    for(int i=100;i>=0;i--)

    {

        temp+=a[i]*x;

        a[i]=temp%base;

        temp=temp/base;

    }

}

void output()

{

   int i=1;

   while(!a[i])

        i++;

   printf("%d",a[i]);//********假如第一位a[1]=34,a[2]=2039,则只能输出343029,而不能输出00342039,所以a[1]需                                                //   要单独列出来输出

   for(i++;i<=100;i++)

printf("%04d",a[i]);//右对齐,左边不足的位数补0,例如假设,a[19]=1234,a[20]=34,a{21]=789则这一段的输出

//就为123400340789;

printf("\n");

}

void chu(int x)

{

    int i=1,temp=0;

    while(!a[i])

       i++;

    for(;i<=100;i++)

       {

           temp=a[i]+temp*base;

           a[i]=temp/x;

           temp%=x;

       }

}

int main()

{

    int m,n,cas=0;

    while(~scanf("%d %d",&m,&n)&&(m||n))

    {

        cas++;

        printf("Test #%d:\n",cas);

        if(n>m)  {cout<<"0"<<endl;}

        else{

        memset(a,0,sizeof(a));

         multiply(m+n);

        chen(m-n+1);

        chu(m+1);

        output();

        }

    }

    return 0;

}

/*****受益匪浅的一道题,这道题综合性还是有点强的,首先卡特兰数推出公示后(公式我推了出来),但是因为数字实在太大(毕竟100的阶乘),所以必需对大数进行处理,也就是高精度,很有技巧性的是,可以让数组一个单元存储一万,而不是以前习惯的十(毕竟数太大),最后还有一个非常关键的地方,就是最终的输出(我个人觉得输出才是本题高潮,最有戏剧性的一部分),具体输出可见代码上的注释,最后,悲催的是发现自己很多题目没有把握都是因为不会时间复杂度以及内存存储大小的分析,是时候好好看看这两个知识点了****/

hdu 1133 卡特兰 高精度的更多相关文章

  1. hdu 1133(卡特兰数变形)

      题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133   题意:排队买50块一张的票,初始票台没有零钱可找,有m个人持有50元,n人持有100元, ...

  2. Buy the Ticket HDU 1133 卡特兰数应用+Java大数

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

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

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

  4. hdu 1023 卡特兰数+高精度

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  6. HDU 1133 Buy the Ticket 卡特兰数

    设50元的人为+1 100元的人为-1 满足前随意k个人的和大于等于0 卡特兰数 C(n+m, m)-C(n+m, m+1)*n!*m! import java.math.*; import java ...

  7. 【noi 2.6_9288】&【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度除法)

    题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变 ...

  8. Hdu 5568 sequence2 高精度 dp

    sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...

  9. hdu 1042 N!(高精度乘法 + 缩进)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...

随机推荐

  1. Python第三方库资源

    [转载]Python第三方库资源   转自:https://weibo.com/ttarticle/p/show?id=2309404129469920071093 参考:https://github ...

  2. Pygame小游戏练习二

    @Python编程从入门到实践 Python项目练习 四.创建Ship类 建立ship.py,创建Ship类,管理飞船行为. # ship.py import pygame class Ship(): ...

  3. golang之工厂模式

    说明: golang的结构体没有构造函数,通常可以使用工厂模式来解决这个问题 如果包里面的结构体变量首字母小写,引入后,不能直接使用,可以工厂模式解决: ch1.go package ch1 type ...

  4. 学习BM算法

    BM算法: 希望大家别见怪,当前博客只用于个人记录所用. [例题]Poor God Water 题意: 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物, 1.这三个食物不能都相同: 2.若三 ...

  5. 怎样修改 VS Code 主题?

    方法1. 点击左上角 File > Preferences > Color Theme. 方法2. 使用快捷键: Ctrl + K , Ctrl + T  PS: 查询各种操作的快捷键可以 ...

  6. grpc的demo

    一 grpc的为什么比http快? 1- 用Proto Buffer 作为序列化工具 2- 采用http2协议,头部压缩,多路复用 3- 基于netty的IO框架 二 grpc的demo A lib工 ...

  7. async/await 的引用

    static async void Start() { string s = "ass"; Console.WriteLine(getMemory(s)+"Hello W ...

  8. ASE19团队项目alpha阶段model组 scrum3 记录

    本次会议于11月5日,19时整在微软北京西二号楼sky garden召开,持续25分钟. 与会人员:Jiyan He, Kun Yan, Lei Chai, Linfeng Qi, Xueqing W ...

  9. 获取impala下所有的数据库建表语句

    方法一: 现在的导出还是有缺陷的,导出的文件中还是存在其他不必要的信息 #!/bin/bash ##获取数据库 databases=$(hive -e "show databases; ex ...

  10. 01.Zabbix监控快速入门

    1.监控知识基本概述 1.为什么要使用监控 1.对系统不间断实时监控 2.实时反馈系统当前状态 3.保证服务可靠性安全性 4.保证业务持续稳定运行 2.如何进行监控,比如我们需要监控磁盘的使用率 1. ...