hdu 1133 卡特兰 高精度
Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5566 Accepted Submission(s): 2326
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 0
3 1
3 3
0 0
Test #1:
6
Test #2:
18
Test #3:
180
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define base 10000
int a[101];
void multiply(int x)
{
a[100]=1;
for(int i=1;i<=x;i++)
for(int j=100,temp=0;j>=0;j--)
{
temp+=a[j]*i;
a[j]=temp%base;
temp=temp/base;
}
}
void chen(int x)
{
int temp=0;
for(int i=100;i>=0;i--)
{
temp+=a[i]*x;
a[i]=temp%base;
temp=temp/base;
}
}
void output()
{
int i=1;
while(!a[i])
i++;
printf("%d",a[i]);//********假如第一位a[1]=34,a[2]=2039,则只能输出343029,而不能输出00342039,所以a[1]需 // 要单独列出来输出
for(i++;i<=100;i++)
printf("%04d",a[i]);//右对齐,左边不足的位数补0,例如假设,a[19]=1234,a[20]=34,a{21]=789则这一段的输出
//就为123400340789;
printf("\n");
}
void chu(int x)
{
int i=1,temp=0;
while(!a[i])
i++;
for(;i<=100;i++)
{
temp=a[i]+temp*base;
a[i]=temp/x;
temp%=x;
}
}
int main()
{
int m,n,cas=0;
while(~scanf("%d %d",&m,&n)&&(m||n))
{
cas++;
printf("Test #%d:\n",cas);
if(n>m) {cout<<"0"<<endl;}
else{
memset(a,0,sizeof(a));
multiply(m+n);
chen(m-n+1);
chu(m+1);
output();
}
}
return 0;
}
/*****受益匪浅的一道题,这道题综合性还是有点强的,首先卡特兰数推出公示后(公式我推了出来),但是因为数字实在太大(毕竟100的阶乘),所以必需对大数进行处理,也就是高精度,很有技巧性的是,可以让数组一个单元存储一万,而不是以前习惯的十(毕竟数太大),最后还有一个非常关键的地方,就是最终的输出(我个人觉得输出才是本题高潮,最有戏剧性的一部分),具体输出可见代码上的注释,最后,悲催的是发现自己很多题目没有把握都是因为不会时间复杂度以及内存存储大小的分析,是时候好好看看这两个知识点了****/
hdu 1133 卡特兰 高精度的更多相关文章
- hdu 1133(卡特兰数变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题意:排队买50块一张的票,初始票台没有零钱可找,有m个人持有50元,n人持有100元, ...
- Buy the Ticket HDU 1133 卡特兰数应用+Java大数
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- 【HDU 1133】 Buy the Ticket (卡特兰数)
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...
- hdu 1023 卡特兰数+高精度
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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元的人为+1 100元的人为-1 满足前随意k个人的和大于等于0 卡特兰数 C(n+m, m)-C(n+m, m+1)*n!*m! import java.math.*; import java ...
- 【noi 2.6_9288】&【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度除法)
题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变 ...
- Hdu 5568 sequence2 高精度 dp
sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...
- hdu 1042 N!(高精度乘法 + 缩进)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...
随机推荐
- macos catalina安装python3
之前跟着教程用brow安装了python3,后来发现电脑上有三个版本的python,头大. 于是用brew uninstall --force python3卸掉了python3 看到现在有两个版本 ...
- 前端模拟数据接口json-server
今天要找帮前端找一个可以实现数据接口模拟的工具.首先看到的mock.js这个.但是这个需要在页面里插入Mock.js我是要给小程序使用,所以不能这么插入.然后又找到了json-server这个Node ...
- MySQL_Utilities工具
需求 Python 2.6 MySQL Connector/Python 连接器 下载地址: http://dev.mysql.com/downloads/utilities/ ...
- k8s-prometheus 数据采集(node redis kubelet等)
apiVersion: v1 kind: ConfigMap metadata: name: prometheus-config namespace: kube-ops data: prometheu ...
- 【原创】大叔经验分享(83)impala执行多个select distinct
impala在一个select中执行多个count distinct时会报错,比如执行 select key, count(distinct column_a), count(distinct col ...
- 【图像处理 】 一、OSTU分割法
图像中像素的灰度值小于阈值T的像素个数记作N0,像素灰度大于阈值T的像素个数记作N1,则有: 图像大小:M*N T为二值化的阈值: N0为灰度小于T的像素的个数,N0的平均灰度为μ0 N1 为灰度大于 ...
- arcgis js之地图分屏同步
arcgis js之地图分屏同步 原理: 新建两个map两个view或者一个map两个view.对地图进行移动事件绑定,在地图移动时同步地图方位 代码: views.forEach((view) =& ...
- js重点——作用域——内部原理(二)
本篇是深入分析和理解作用域的第一篇——内部原理和工作模型. 我们知道作用域是变量,对象,函数可访问的一个范围.这说明了我们需要一套良好的规则来存储变量,之后方便查找.所以我们首先要理解的是在哪里而且怎 ...
- vue项目在IE浏览器和360兼容模式下页面不显示问题,亲测有效
解决方法:安装 "babel-polyfill" 1.命令:cnpm install --save-dev babel-polyfill 2.在入口main.js文件引入:impo ...
- django-bootstrap4|django 加载popper.min.js失败
1.现象 2.解决过程 2.1.右键查看网页源代码 在浏览器地址栏打开popper.min.js对应的URL,发现无法打开,这个地址是国外的,需要找一个可访问的地址替换. 2.2.找到URL在djan ...