Buy the Ticket HDU 1133
传送门
[http://acm.hdu.edu.cn/showproblem.php?pid=1133]
题目描述和分析



代码
#include<iostream>
#include<string.h>
using namespace std;
void Multiply(int a[],int z)//大数a[]和小数z相乘,结果存储在a[]中
{
int maxn = 2000;
int c = 0;
for(int j=maxn-1;j>=0;j--)//用z乘以a[]的每一位
{
int x = a[j] * z + c;
a[j] = x % 10;
c = x / 10;
}
}
int main()
{
int m,n,num=0;
while(1)
{
cin >> m >> n;
if(!m && !n)
break;
cout << "Test #" << ++num << ":" << endl;
if(m<n)//m<n,没有符号条件的排列
{
cout << 0 << endl;
continue;
}
const int maxn = 2000;
int a[maxn],i,j;
memset(a,0,sizeof(a));
a[maxn-1] = 1;
if(n==0)//此时全是拿50元的人,直接输出m!的结果
for(i=2;i<=m+n;i++)//计算m!
Multiply(a,i);
else if(n>=1)//此时按照公式计算,避开除法
{
for(i=2;i<=m+n;i++)
if(i!=m+1)//如果,某一项恰好是分母(m+1),则不乘以这一项
Multiply(a,i);
Multiply(a,m-n+1);//根据公式,最后还要乘以(m-n+1)一项
}
for(i=0;i<maxn;i++)
if(a[i])//从i开始,非零
break;
for(j=i;j<maxn;j++)//输出
cout << a[j];
cout << endl;
}
return 0;
}
Buy the Ticket HDU 1133的更多相关文章
- Buy the Ticket HDU 1133 递推+大数
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元, m个人是只有50元一张的, n个人 ...
- Buy the Ticket HDU 1133 卡特兰数应用+Java大数
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- Buy the Ticket HDU - 1133 大数dp
题意: 演唱会门票售票处,那里最开始没有零钱.每一张门票是50元,人们只会拿着100元和50元去买票,有n个人是拿着50元买票,m个人拿着100元去买票. n+m个人按照某个顺序按序买票,如果一个人拿 ...
- 【HDU 1133】 Buy the Ticket (卡特兰数)
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...
- 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)To ...
- HDU——1133 Buy the Ticket
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)To ...
- HDUOJ---1133(卡特兰数扩展)Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- Mysql基础之 ALTER命令
ALTER命令: 作用:当我们修改数据库的列属性.列名称.表名等,要使用ALTER命令 教程: 1.首先是我们创建一个数据库以及一张表 mysql> create table exercise( ...
- 【BZOJ4259】残缺的字符串
[BZOJ4259]残缺的字符串 Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时, ...
- eclipse 右键发现没有 build-path
1)确认下是否有.project和.classPath文件 2)点击右上角按钮先切换到java下,默认方式是javaEE 然后就能出现build path了 这是build path 子项为灰色,依然 ...
- cmd 监控网络状况
提示:如果提示curl不是内部命令,请自行百度 windows 安装curl @echo off color 1f title 正在监控 echo 正在监控http://ioscheck.duapp. ...
- PID控制本版一 (M100可用)
版本1 云台+无人机 https://en.wikipedia.org/wiki/PID_controller https://github.com/tekdemo/MiniPID 详细讲解 PIDC ...
- ROS 订阅图像节点
博客 http://blog.csdn.net/github_30605157/article/details/50990493 参考ROS原网站 http://wiki.ros.org/image_ ...
- webstorm 设置 sass自动编译问题
sass语法.使用它带来的好处,就不再这里做介绍了,主要看怎么在webstorm里配置自动编译. sass编译是需要Ruby环境的,可以到这里去下载 : https://rubyinstaller ...
- [转]Qt状态栏(statusbar)的使用
状态栏显示的信息分3种 1. 一般信息,用QLabel 代表 2. 永久信息,文本会一直显示在状态栏的最右边. 3. 临时信息,指定信息现实的时间.时间到即信息消失 QLabel *locationL ...
- PAT A1102 Invert a Binary Tree (25 分)——静态树,层序遍历,先序遍历,后序遍历
The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ( ...
- Tensorflow[LSTM]
0.背景 通过对<tensorflow machine learning cookbook>第9章第3节"implementing_lstm"进行阅读,发现如下形式可以 ...