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 ...
随机推荐
- [HDFS_add_1] HDFS 启动过程分析
0. 说明 HDFS 文件概念 && HDFS 启动过程分析 1. HDFS 文件概念 [1.1 NameNode 职能] 存储文件类型.大小.权限.路径等等元数据 通过 edits( ...
- win7下面搭建angularjs开发环境
每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code 1.安装git,添加环境变量2.github上有一个比较好的纯净AngularJs app的种 ...
- reorder-list 单链表
题意: 给你一个单链表 a1 a2 a3 a4 a5....an 让你变成 a1 an a2 an-1 a3 an-2 .... 这里牵涉到,单链表的倒置和两个单链表的合并. class Soluti ...
- tomcat8_java1.8 基础镜像
需要解决的越来越多, 基础镜像中 添加 cronolog功能,用于切割catalina.out 日志. 思路是: cephfs 挂载在node节点, crontab 删除 几天的tomcaat 日志. ...
- Arduino IDE for ESP8266 (4)局域网 网页图形化控制灯 路由系统
用到的路由系统文件(备用) 链接:https://pan.baidu.com/s/1bqR7Lc7 密码:7w2z 教程http://www.windworkshop.cn/?p=1274
- Arduino IDE for ESP8266教程(二) 创建WIFI AP模式
创建WIFI热点 #include <ESP8266WiFi.h> void setup() { Serial.begin ( 115200 ); Serial.println(" ...
- Python高级网络编程系列之第三篇
在高级篇二中,我们讲解了5中常用的IO模型,理解这些常用的IO模型,对于编写服务器程序有很大的帮助,可以提高我们的并发速度!因为在网络中通信主要的部分就是IO操作.在这一篇当中我们会重点讲解在第二篇当 ...
- Linux系统学习之网络管理
网络接口配置 使用ifconfig检查和配置网卡 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ...
- Linux 安装erlang
安装rabbitmq的基础erlang1. 下载erlang 版本:otp_src_20.1.tar.gz 地址: http://erlang.org/download/?M=D 2.安装erlang ...
- Omi框架学习之旅 - 生命周期 及原理说明
生命周期 name avatars company constructor 构造函数 new的时候 install 初始化安装,这可以拿到用户传进的data进行处理 实例化 installed 安装完 ...