题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=1133

【题意】

电影票50块一张

有m个人手里正好有50块,n个人手里正好有100块,售票厅開始没有钱。问,有多少种排队的方式,能够让每一个人都买上票。

(假设售票厅没有50块零钱,则持有100块的人买不了票)

【分析】

显然。当m<n的时候,有0种排列方式。

当m>=n的时候:

用0。代表手里仅仅有50块的人,1,代表手里仅仅有100块的。

则0110100 这样的情况不能满足条件(到第三个人就买不了)

我们把包含第三个人及他之前的人 翻转 (1->0,  0->1)

1000100 出现了这个序列;

0110100   有 4个0,3个1   
1000100  有5个0 ,2个1

每个不能满足的情况都相应这样一个序列 所以 不能满足的条件的情况共同拥有

C(m+1,m+n);

我们计算公式就是:合法的排列方式=全部排列方式-非法排列方式

于是就有了F(N)=(-)*m!*n! 

然后再化简一下;

F(N) =(m+n)!

*(m-n+1)/(m+1)。

由于数据过大,所以用了JAVA大数来解决

【代码】

import java.util.*;
import java.math.BigInteger;
public class Main{
public static void main(String[] args){
int a,b;
Scanner in=new Scanner(System.in);
int cnt=0;
while(in.hasNext()){
cnt++;
a=in.nextInt();
b=in.nextInt();
BigInteger ans=BigInteger.ONE;
if(a==0&&b==0)break;
if(a<b) ans=BigInteger.ZERO;
else {
for(int i=1;i<=a+b;i++){
ans=ans.multiply(BigInteger.valueOf(i));
}
int mpl=(a-b+1);
int dvd=(a+1);
ans=ans.multiply(BigInteger.valueOf(mpl));
ans=ans.divide(BigInteger.valueOf(dvd));
}
System.out.println("Test #"+cnt+":");
System.out.println(ans);
}
}
}

hdu1133 Buy the Ticket (卡兰特数应用+java大数)的更多相关文章

  1. HDU1133 Buy the Ticket —— 卡特兰数

    题目链接:https://vjudge.net/problem/HDU-1133 Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Me ...

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

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

  3. Buy the Ticket(卡特兰数+递推高精度)

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

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

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

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

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

  6. 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket

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

  7. Buy the Ticket{HDU1133}

    Buy the TicketTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. HDUOJ---1133(卡特兰数扩展)Buy the Ticket

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

  9. hdu 1133 Buy the Ticket(Catalan)

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

随机推荐

  1. spring踩坑

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...

  2. vue 单独页面定时器 离开页面销毁定时器

    data: { return { timer: null } }, created() { this.timer = setInterval(....); }, beforeDestroy() { i ...

  3. @ApiParam @RequestParam @PathVariable 用法

    文章来源:https://www.cnblogs.com/hello-tl/p/9204279.html 1.@ApiParam ,是注解api的参数 ,也就是用于swagger提供开发者文档 ,文档 ...

  4. PHP调用webService WSDL 接口发送邮件

    1.什么是 webService WSDL?  webService WSDL 暴露一些接口给第三方调用,在底层会转化成一个HTTP请求,主要是不同语言之间为了通讯的一个协议,比如发送邮件的系统是用J ...

  5. 剑指Offer(书):二叉树的下一个节点

    题目:给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 分析:若一个节点有右子树,那么他的下一个节点就是他右子树中 ...

  6. jQuery+ajax城市联动

    分享一下自己最近写的城市联动.技术使用ajax+jQuery实现. 首先请看前台的javascript代码. 以下是连个实现异步加载的方法. <script type="text/ja ...

  7. Android版网易云音乐唱片机唱片磁盘旋转及唱片机机械臂动画关键代码实现思路

     Android版网易云音乐唱片机唱片磁盘旋转及唱片机机械臂动画关键代码实现思路 先看一看我的代码运行结果. 代码运行起来初始化状态: 点击开始按钮,唱片机的机械臂匀速接近唱片磁盘,同时唱片磁盘也 ...

  8. uva 1364

    刘书上例题 #include <cstdio> #include <cstdlib> #include <cmath> #include <set> # ...

  9. spring-security 理解 笔记 介绍以及使用(持续更新)

    本人经过2周的学习,成功搭建了认证服务器,资源服务器和客户端 .下面是本人对 oauth2的理解,以及spring-security的使用,如果理解错误的地方,还望指正. 现在代码有点凌乱,过段时间会 ...

  10. CSS3 水波纹

    css3 动画设置水波纹,效果如下图: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta ...