hdu 1133 Buy the Ticket(Catalan)

时间:2020-12-24 09:38:20

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 &lpar;大数&plus;递推&rpar;

    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&sol;HDU 1133 Buy the Ticket&lpar;数论~卡特兰数~大数~&rpar;

    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&period;2612 Find a way (BFS)

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

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

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

随机推荐

  1. angularJS(6)

    angularJS(6) 一:angularJs的事件. 1.ng-click指令定义了AngularJS点击事件. <div ng-app="myapp" ng-contr ...

  2. FunDA(2)- Streaming Data Operation:流式数据操作

    在上一集的讨论里我们介绍并实现了强类型返回结果行.使用强类型主要的目的是当我们把后端数据库SQL批次操作搬到内存里转变成数据流式按行操作时能更方便.准确.高效地选定数据字段.在上集讨论示范里我们用集合 ...

  3. shell if

    shell中if做比较 比较两个字符串是否相等的办法是: if [ "$test"x = "test"x ]; then 这里的关键有几点: 1 使用单个等号 ...

  4. ovs &plus; kernel datapath 的分片与重组流程

    非VXLAN的收发包调用栈 netdev_frame_hook()      netdev_port_receive()           ovs_vport_receive()           ...

  5. Django&plus;xadmin打造在线教育平台(十)

    十四.xadmin的进阶开发 14.1.权限管理 (1)用户权限 超级用户拥有所有权限,其它添加的用户默认没有任何权限 进后台添加一个用户“Editor1”,勾上“职员状态”后,这个用户才可以登录进后 ...

  6. CenOS常用命令

    reset  作用:清屏 cd Change the shell working dirctory 切换工作目录 用法 输入cd+“空格”+“/”+“目录” 示例:cd /home 切换到home目录 ...

  7. spring mvc 跨域问题。。。解决

    官方推荐方式: http://spring.io/blog/2015/06/08/cors-support-in-spring-framework 方式1: $.ajax({ //前台:常规写法.注意 ...

  8. unigui作中间件使用

    unigui作中间件使用 可返回string或者tstream数据. 如果返回JSON字符,则UNIGUI就是REST 中间件. procedure TUniServerModule.UniGUISe ...

  9. Java判断多个时间段是否重叠&lpar;重叠区间个数&rpar;

    import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * 判断多个时间段是否出现重叠 ...

  10. API接口安全加强设计方法

    前面两篇相关文章: <Web Api 内部数据思考 和 利用http缓存优化 Api> <Web Api 端点设计 与 Oauth> 1.开放的接口 这样的接口我们天天都在接触 ...