Buy the Ticket

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

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
HUANG, Ninghai

题意:

m個人拿50,n個人拿100,而且售票处没有零钱。求这排人最终能够能全买到票的方案数

(如果没有50零钱找给拿一百的人则停)。

思路:

排列的所有可能情况:C(n+m,m)

假设一个数列 0110010当买到第三个人的时候便停止了,将后面的数1->0,0->1便能得到 0111101

反之亦然,于是我们可以得出他们是一一对应的。

于是我们用所有可能减去不成立的

(C(n+m,m) - C(n+m,m+1))*m!*n! = (n+m)! * (m-n+1) / (m+1);

然后再利用JAVA的大整数即可

import java.math.BigInteger;
import java.util.Scanner; public class Main { static BigInteger []F = new BigInteger[105];
static BigInteger []A = new BigInteger[205];
public static void ini()
{
F[1] = BigInteger.valueOf(1);
A[1] = BigInteger.valueOf(1);
A[0] = BigInteger.valueOf(0);
F[0] = F[1];
for(int i = 2;i < 105;i++)
{
F[i] = F[i-1].multiply(BigInteger.valueOf(i*4-2)).divide(BigInteger.valueOf(i+1));
}
for(int i = 2;i <= 203;i++)
{
A[i] = A[i-1].multiply(BigInteger.valueOf(i));
}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
ini();
Scanner Reader = new Scanner(System.in);
int x,y;
int cas = 1;
BigInteger ans;
while(true)
{
x = Reader.nextInt();
y = Reader.nextInt(); if(x == 0 && y == 0)
break;
System.out.println("Test #"+cas+":");
cas++;
if(x < y){
System.out.println("0");
}
else
{
int t = x+y;
ans = A[t].multiply(BigInteger.valueOf(x-y+1)).divide(BigInteger.valueOf(x+1));
System.out.println(ans);
}
}
} }

  

hdu 1133 Buy the Ticket(Catalan)的更多相关文章

  1. HDU 1133 Buy the Ticket (数学、大数阶乘)

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

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

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

  3. HDU——1133 Buy the Ticket

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

  4. Buy A Ticket(图论)

    Buy A Ticket 题目大意 每个点有一个点权,每个边有一个边权,求对于每个点u的\(min(2*d(u,v)+val[v])\)(v可以等于u) solution 想到了之前的虚点,方便统计终 ...

  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的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...

  7. 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 ...

  8. HDU.2612 Find a way (BFS)

    HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...

  9. HDU.1233 还是畅通工程(Prim)

    HDU.1233 还是畅通工程(Prim) 题意分析 首先给出n,代表村庄的个数 然后出n*(n-1)/2个信息,每个信息包括村庄的起点,终点,距离, 要求求出最小生成树的权值之和. 注意村庄的编号从 ...

随机推荐

  1. Java HashMap工作原理及实现

    Java HashMap工作原理及实现 2016/03/20 | 分类: 基础技术 | 0 条评论 | 标签: HASHMAP 分享到:3 原文出处: Yikun 1. 概述 从本文你可以学习到: 什 ...

  2. 不看就亏了:DELL EqualLogic PS6100详解及数据恢办法

    DELL EqualLogic PS6100采用虚拟ISCSI SAN阵列,为远程或分支办公室.部门和中小企业存储部署带来企业级功能.智能化.自动化和可靠性,支持VMware.Solaris.Linu ...

  3. EasyUI 中easyui-textbox和easyui-searchbox文本框的点击事件。

    html: <input id="txtsearch" class="easyui-textbox" data-options="buttonT ...

  4. Mysql主从复制架构实战

    [root@Mysql-master ~]# vim /etc/my.cnf log-bin=mysql-bin server-id = 1  #slave端server-id值改成2 mysql&g ...

  5. 一种dubbo逻辑路由方案

    背景介绍 现在很多的公司都在用dubbo.springcloud做为服务化/微服务的开发框架,服务化之后应用越来越多,链路越来越长,服务环境的治理变的很困难.比如:研发团队的人很多的,同时有几个分支在 ...

  6. SpringCloud的部署模型

    http://www.th7.cn/Program/java/201608/919853.shtml

  7. SpringMVC架构的项目,js,css等静态文件导入有问题

    发生原因 <servlet> <servlet-name>springmvc-mybaits</servlet-name> <servlet-class> ...

  8. ssh_maven之controller层开发

    我们已经完成了前两层的开发,现在 只剩下我们的controller层了,对于这一层,我们需要创建一个动作类CustomerAction,另外就是我们的strutss.xml以及我们的applicati ...

  9. CentOS 6.5 Tomcat安装及配置

    1.安装jdk,配置jdk环境(此步骤略过) 2.下载安装tomcat 百度网盘链接: https://pan.baidu.com/s/1Ieejo7TQyzRAVPhQft8Phw 密码: dg2v ...

  10. 表单中各种input汇总

    html表单 表单用于搜集不同类型的用户输入,表单由不同类型的标签组成,相关标签及属性用法如下: 1.<form>标签 定义整体的表单区域 action属性 定义表单数据提交地址 meth ...