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. XCode Build Settings中几种Search Paths

    Header search path:去查找头文件的路径,同在在你需要使用第三方库的时候,在这里设置你的头文件路径目录,如图 <code><span class="str& ...

  2. c 语言常量

    1,整数常量 整数常量可以是十进制.八进制或十六进制的常量.前缀指定基数:0x 或 0X 表示十六进制,0 表示八进制,不带前缀则默认表示十进制. 整数常量也可以带一个后缀,后缀是 U 和 L 的组合 ...

  3. 粒子系统(二):Canvas绘制精美图案

    准备 IDE:Visual Studio Code Language:JavaScript / ECMAScript 6+ GitHub:Natural2D.JS 本文主要讲述 Particles - ...

  4. WebBench的安装与使用

    webbench最多可以模拟3万个并发连接去测试网站的负载能力. 一.编译安装 1.上传压缩包到虚机里,rz webbench-1.5.tar.gz 2.解压 tar zxvf webbench-1. ...

  5. 转:java中Vector的使用

    转:https://www.cnblogs.com/zhaoyan001/p/6077492.html Vector 可实现自动增长的对象数组. java.util.vector提供了向量类(vect ...

  6. Django 使用celery任务队列的配置

    celery 情景:用户发起request,并等待response返回.在本些views中,可能需要执行一段耗时的程序,那么用户就会等待很长时间,造成不好的用户体验,比如发送邮件.手机验证码等. 使用 ...

  7. python中文编码坑

    打印list的时候unicode对象不会自动转为中文!

  8. TreeMap就这么简单【源码剖析】

    前言 声明,本文用得是jdk1.8 前面章节回顾: Collection总览 List集合就这么简单[源码剖析] Map集合.散列表.红黑树介绍 HashMap就是这么简单[源码剖析] LinkedH ...

  9. xpath的一般用法与特殊用法

    # xpath的使用 安装lxml from lxml import etree Selector = etree.HTML(网页代码) Selector.xpath(一段神奇的代码) xpath的一 ...

  10. 类相关的BIF

    1.>>> issubclass(C,A)#判断c是A的子类,返回真假 2.>>> isinstance(b1,B) #判断c1是B类的实例化对象,返回真假 3.& ...