Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4981 Accepted Submission(s): 2085
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.
3 1
3 3
0 0
6
Test #2:
18
Test #3:
180
#include<cstdio>
#include<cstring>
int a[390];
int n,m,leap;
void bfact(int n)
{
int i,j;
for(i=2; i<=n; i++)
{
if(leap&&i==m+1) continue;
int c=0,s;
for(j=0; j<380; j++)
{
s=i*a[j]+c;
a[j]=s%10;
c=s/10;
}
} } void bx(int n)
{
int j;
int s,c=0;
for(j=0; j<380; j++)
{
s=n*a[j]+c;
a[j]=s%10;
c=s/10;
} }
int main()
{
//freopen("case.in","r",stdin);
int i,j,c=1;
while(scanf("%d%d",&m,&n)!=-1)
{
if(!m&&!n) break;
leap=0;
memset(a,0,sizeof(a));
a[0]=1;
printf("Test #%d:\n",c);
if(m<n)
{
printf("0\n");
c++;
continue;
}
if((m-n+1)%(m+1)==0)
bx((m-n+1)/(m+1));
else
{
bx(m-n+1);
leap=1;
}
bfact(n+m);
for(i=380; i>=0; i--)
if(a[i]) break;
for(j=i; j>=0; j--)
printf("%d",a[j]);
printf("\n");
c++;
}
}
//从网上找到了公式 即:结果等于 (m+n)!*(m-n+1)/(m+1)
//那么这题就是高精度问题了
Buy the Ticket的更多相关文章
- Buy the Ticket{HDU1133}
Buy the TicketTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 【HDU 1133】 Buy the Ticket (卡特兰数)
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...
- 【高精度练习+卡特兰数】【Uva1133】Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Buy the Ticket(卡特兰数+递推高精度)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- hdu 1133 Buy the Ticket(Catalan)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)
题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...
- HDUOJ---1133(卡特兰数扩展)Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Codeforces 938.D Buy a Ticket
D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- hdu 1133 Buy the Ticket (大数+递推)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Codeforces 938D Buy a Ticket (转化建图 + 最短路)
题目链接 Buy a Ticket 题意 给定一个无向图.对于每个$i$ $\in$ $[1, n]$, 求$min\left\{2d(i,j) + a_{j}\right\}$ 建立超级源点$ ...
随机推荐
- Visual Studio 2015 各版本神KEY
Visual Studio 2015 简体中文专业版专业版神Key:HMGNV-WCYXV-X7G9W-YCX63-B98R2 Visual Studio 2015 繁体中文企业版企业版神Key1:H ...
- thinkphp中模块和操作映射
模板和操作映射功能是3.1.2版本支持的对模块和操作设置的映射机制,由于可以通过改变配置动态改变(实际真正改变,并非别名)URL访问地址,加强了应用的安全性,而且,映射机制具有URL不区分大小写访问的 ...
- RHEL 6.0使用CentOS yum源
引言:由于RHEL的yum在线更新是收费的,如果没有注册的话是不能使用的,即不能在线安装软件.在这种情况下,想使用RHEL系统,还想用yum源来在线安装软件,有没有办法?答案是有办法,请往下看! 1. ...
- 转:PCL+VS2010环境配置
1.下载 http://www.pointclouds.org/downloads/windows.html出下载PCL完全安装包1.6.0 all-in-one-installer,我的电脑是32位 ...
- HashMap实现原理分析(详解)
1. HashMap的数据结构 http://blog.csdn.net/gaopu12345/article/details/50831631 ??看一下 数据结构中有数组和链表来实现对数据的存 ...
- Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
- Solr5.3.1 SolrJ查询索引结果
通过SolrJ获取Solr检索结果 1.通过SolrParams的方式提交查询参数 SolrClient solr = new HttpSolrClient("http://localhos ...
- Java web项目的字符集问题
如果在Windows系统下使用eclipse开发Java应用,那么开始的时候我们一般不会考虑编码问题,但是随着不断学习,接触到前端.服务端.数据接口.数据库等更多的组件时,编码问题就逐渐暴露出来了,我 ...
- 让Delphi的DataSnap发挥最大效率
让Delphi的DataSnap发挥最大效率 让Delphi的DataSnap发挥最大效率 一个DataSnap的应用程序由两个层组成: DataSnap服务器,它有一个带有一个或者更多DataSet ...
- Java for LeetCode 058 Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...