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 ...
随机推荐
- 机器学习中学习曲线的 bias vs variance 以及 数据量m
关于偏差.方差以及学习曲线为代表的诊断法: 在评估假设函数时,我们习惯将整个样本按照6:2:2的比例分割:60%训练集training set.20%交叉验证集cross validation set ...
- linux 下正则匹配时间命名格式的文件夹
用正则表达式匹配时间格式命名的文件夹 ls mypath | grep -E "[0-9]{4}-[0-9]{1,2}" mypath为需要查询的目录 查询出来的文件夹格式为:例 ...
- 如何开启win10的上帝模式
用了这么久的电脑,小编才知道还有“上帝模式”这一说,原谅小编的孤陋寡闻.翻阅资料才知道,上帝模式简单来说就是一个全能的控制面板,如控制面板的功能.界面个性化.辅助功能选项等方方面面的控制设置,几乎包含 ...
- PHP实现简单下载功能
PHP实现简单下载 PHP文件为download.php,供下载的文件为1.jpg. <?php $filename="1.jpg"; if(!file_exists($fi ...
- android 布局文件中xmlns:android="http://schemas.android.com/apk/res/android"
http://blog.163.com/benben_long/blog/static/199458243201411394624170/ xmlns:android="http://sch ...
- 如何使用openscad绘制一个简单的键帽.
1 新建空项目 2测数据 测量得出数据.这个长方体的长宽高分别是1.6.4.6.8 注意,这三个数据并不是测量得到的数据,而且加了一点公差值(为3D打印做准备) 3画图 写代码 导入模型 为了方便以后 ...
- day12 Python列表
list#类 列表概括 li = [1,2,13,["石振文",["19", 10],"庞麦郎"],"charon",& ...
- Linux安装consul
1.下载并解压consul # cd /opt/ # mkdir consul # chmod 777 consul #cd consul #wget https://releases.hashico ...
- POST提交数据之---Content-Type的理解;
POST提交数据之---Content-Type的理解: Content-Type是指http/https发送信息至服务器时的内容编码类型,contentType用于表明发送数据流的类型,服务器根据编 ...
- PAT A1097 Deduplication on a Linked List (25 分)——链表
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated ...