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的大整数即可

  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6. static BigInteger []F = new BigInteger[105];
  7. static BigInteger []A = new BigInteger[205];
  8. public static void ini()
  9. {
  10. F[1] = BigInteger.valueOf(1);
  11. A[1] = BigInteger.valueOf(1);
  12. A[0] = BigInteger.valueOf(0);
  13. F[0] = F[1];
  14. for(int i = 2;i < 105;i++)
  15. {
  16. F[i] = F[i-1].multiply(BigInteger.valueOf(i*4-2)).divide(BigInteger.valueOf(i+1));
  17. }
  18. for(int i = 2;i <= 203;i++)
  19. {
  20. A[i] = A[i-1].multiply(BigInteger.valueOf(i));
  21. }
  22. }
  23. public static void main(String[] args) {
  24. // TODO 自动生成的方法存根
  25. ini();
  26. Scanner Reader = new Scanner(System.in);
  27. int x,y;
  28. int cas = 1;
  29. BigInteger ans;
  30. while(true)
  31. {
  32. x = Reader.nextInt();
  33. y = Reader.nextInt();
  34.  
  35. if(x == 0 && y == 0)
  36. break;
  37. System.out.println("Test #"+cas+":");
  38. cas++;
  39. if(x < y){
  40. System.out.println("0");
  41. }
  42. else
  43. {
  44. int t = x+y;
  45. ans = A[t].multiply(BigInteger.valueOf(x-y+1)).divide(BigInteger.valueOf(x+1));
  46. System.out.println(ans);
  47. }
  48. }
  49. }
  50.  
  51. }

  

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. vmware ubuntu蓝屏

    ctrl+alt+f4 sudo apt-get update sudo apt-get upgrade sudo apt-get install xserver-xorg-lts-utopic su ...

  2. 要学好JAVA要注意些什么?

    从自学开始到参加系统的学习JAVA已经差不多有1个月了的时间了,在这段时间以前我也和很多人一样在网上盲目的搜罗一些视频来自己啃,随着时间的积累,对JAVA的认识也有了一定的提升,之前可能因为在IT咨询 ...

  3. web信息泄露注意事项

    1. 确保您的Web服务器不发送显示有关后端技术类型或版本信息的响应头. 2. 确保服务器打开的端口上运行的所有服务都不会显示有关其构建和版本的信息. 3. 确保所有目录的访问权限正确,保证不会让攻击 ...

  4. Java 持久化操作之 --io流与序列化

    1)File类操作文件的属性 1.File类的常用方法 1. 文件的绝对完整路径:getAbsolutePath() 文件名:getName() 文件相对路径:getPath() 文件的上一级目录:g ...

  5. Electron的代码调试

    刚接触Electron,尝试调试程序时,竟无从下手,所以把这个过程做了下记录 参考工程 根据Electron的官方文档:使用 VSCode 进行主进程调试:https://electronjs.org ...

  6. SpringBoot应用的监控与管理

    spring-boot-starter-actuator模块 /health /autoconfig /beans /configprops:应用配置属性信息 /env:环境属性,如:环境变量.jvm ...

  7. Python 中格式化字符串 % 和 format 两种方法之间的区别

    Python2.6引入了 format 格式化字符串的方法,现在格式化字符串有两种方法,就是 % 和 format ,具体这两种方法有什么区别呢?请看以下解析. # 定义一个坐标值 c = (250, ...

  8. MYSQL之视图、触发器、存储过程、函数、事物、数据库锁和数据库备份

    一.视图 -- view 视图:是一个虚报表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据. 视图有如下特点: 1.视图的列可以来自不同的表,是表的抽象和逻辑意义上建立的新关系 ...

  9. Java并发编程:synchronized和锁优化

    1. 使用方法 synchronized 是 java 中最常用的保证线程安全的方式,synchronized 的作用主要有三方面: 确保线程互斥的访问代码块,同一时刻只有一个方法可以进入到临界区 保 ...

  10. SQL优化(SQL TUNING)之10分钟完成亿级数据量性能优化(SQL调优)

    前几天,一个用户研发QQ找我,如下: 自由的海豚. 16:12:01 岛主,我的一条SQL查不出来结果,能帮我看看不? 兰花岛主 16:12:10 多久不出结果? 自由的海豚 16:12:17 多久都 ...