hdu 1133 Buy the Ticket (大数+递推)
Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4185 Accepted Submission(s): 1759
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.
简单题。推出递推公式就差不多了。
//0 MS 324 KB Visual C++
/* 递推公式:
ans[n][m]=(n+m)!*(n-m+1)/(n+1);
*/
#include<stdio.h>
#include<string.h>
#define N 10000
int f[][]={};
void mul(int a[],int n)
{
int temp=;
for(int i=;i<;i++){
temp+=n*a[i];
a[i]=temp%N;
temp/=N;
}
}
void div(int a[],int n)
{
int temp=;
for(int i=;i>=;i--){
temp=temp*N+a[i];
a[i]=temp/n;
temp%=n;
}
}
void init()
{
f[][]=;
for(int i=;i<=;i++){
memcpy(f[i],f[i-],*sizeof(int));
mul(f[i],i);
}
}
int main(void)
{
int n,m,k=;
init();
while(scanf("%d%d",&n,&m),n+m)
{
printf("Test #%d:\n",k++);
if(m>n){
puts("");continue;
}
int ans[];
memcpy(ans,f[n+m],*sizeof(int));
mul(ans,n-m+);
div(ans,n+); int i=;
for(;!ans[i];i--);
printf("%d",ans[i]);
while(i--) printf("%04d",ans[i]);
printf("\n");
}
return ;
}
hdu 1133 Buy the Ticket (大数+递推)的更多相关文章
- HDU 1133 Buy the Ticket (数学、大数阶乘)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1133 Buy the Ticket(Catalan)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU——1133 Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- hdu 1133 Buy the Ticket
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...
- 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 ...
- HDU 1297 Children’s Queue (递推、大数相加)
Children’s Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU-1041-Computer Transformation,大数递推,水过~~
Computer Transformatio ...
- hdu 5335 Walk Out(bfs+斜行递推) 2015 Multi-University Training Contest 4
题意—— 一个n*m的地图,从左上角走到右下角. 这个地图是一个01串,要求我们行走的路径形成的01串最小. 注意,串中最左端的0全部可以忽略,除非是一个0串,此时输出0. 例: 3 3 001 11 ...
随机推荐
- angular、angular2、vue的生命周期
angular生命周期是什么 1.Angular每个组件都存在一个生命周期,从创建,变更到销毁.Angular提供组件生命周期钩子,把这些关键时刻暴露出来,赋予在这些关键结点和组件进行交互的能力,掌握 ...
- 一张图理解UINavigationBar,UINavigationItem,UIBarButtonItem,UITabBar,UITabBarItem,UITabBarButton
- 【实现高可效的代理模式-Squid】
普通正向代理 首先安装squid代理软件包: 端口控制 在squid server端作端口访问控制,把默认的3128端口改为1000端口 同时把squid服务代理端口添加到selinux安全子系统的允 ...
- pyqt5--学习资料
http://zetcode.com/gui/pyqt5/ http://www.thehackeruniversity.com/2014/01/23/pyqt5-beginner-tutorial/ ...
- Java学习笔记十二:Java中方法的重载
Java中方法的重载 什么是方法的重载呢? 如果同一个类中包含了两个或两个以上方法名相同.方法参数的个数.顺序或类型不同的方法,则称为方法的重载,也可称该方法被重载了.如下所示 4 个方法名称都为 s ...
- JavaScript之this解析
1.解析器在调用函数每次都会向函数内部传递进一个隐含的参数,这个隐含的参数就是this,this指向的是一个对象,这个对象我们称为函数执行的上下文对象,根据函数的调用方式不同,this会指向不同的对象 ...
- 当安装mongodb客户端出现了Failed to load list of databases
在装mongodb最新版(4.1.5开发版)服务后,我用robo3t打开它的时候遇到了这个问题. 最直接的解决办法就是换一个mongodb版本,https://github.com/Studio3T/ ...
- TopCoder SRM 489 Div1 Lev3:AppleTree
挺优秀的一道题,想出做法时有些惊艳. 题意: 数轴上有\(D\)个连续整数刻度,有\(N\)棵树要种在这些刻度上,其中第\(i\)棵与两旁(如果有的话)相邻的树至少要相距\(R_i\),问方法数. \ ...
- ip4addr_ntoa和不可重入函数
在网络中,有一个转换IP地址到ASIIC字符串的函数,该函数的返回值所指向的ASIIC字符串驻留在静态内存中,所以该函数不可重入. 通俗的讲,在多任务系统中,一个任务执行在调用运行这个函数的时候,其他 ...
- mysql ON DUPLICATE KEY UPDATE、REPLACE INTO
INSERT INTO ON DUPLICATE KEY UPDATE 与 REPLACE INTO,两个命令可以处理重复键值问题,在实际上它之间有什么区别呢?前提条件是这个表必须有一个唯一索引或主键 ...