HDOJ 1133 Buy the tickets!
2016-02-02 16:30
267 查看
Problem Description
The "Harry Potter and the Goblet of Fire" will be on show in the next few days. As a crazy fan of Harry Potter, you will go to the cinema and have the first sight, won’t you?
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.
Input
The input file contains several test cases. Each test case is made up of two integer numbers: m and n. It is terminated by m = n = 0. Otherwise, m, n <=100.
Output
For each test case, first print the test number (counting from 1) in one line, then output the number of different ways in another line.
Sample Input
Sample Output
总结该题应用的思路和特别,首先整体上使用了排除法的思路,将不合法的除去剩下的就是合法的了,具体的解析见点击打开链接,在该题中我们还练习了大数/小数且结果是正数的高精度除法
The "Harry Potter and the Goblet of Fire" will be on show in the next few days. As a crazy fan of Harry Potter, you will go to the cinema and have the first sight, won’t you?
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.
Input
The input file contains several test cases. Each test case is made up of two integer numbers: m and n. It is terminated by m = n = 0. Otherwise, m, n <=100.
Output
For each test case, first print the test number (counting from 1) in one line, then output the number of different ways in another line.
Sample Input
3 0 3 1 3 3 0 0
Sample Output
Test #1: 6 Test #2: 18 Test #3: 180// // main.cpp // 1133 // // Created by 张嘉韬 on 16/2/2. // Copyright © 2016年 张嘉韬. All rights reserved. // #include <iostream> #include <cmath> #include <cstring> using namespace std; const int maxn=390; int main() { int m,n,f[maxn],temp,c,len,a,t; t=0; while(scanf("%d%d",&m,&n)==2&&(m||n)) { t++; if(n>m) { cout<<"Test #"<<t<<":"<<endl; cout<<0<<endl; continue; } memset(f,0,sizeof(f)); f[1]=1; for(int i=2;i<=m+n;i++) { c=0; for(int j=1;j<=maxn-1;j++) { temp=f[j]*i+c; f[j]=temp%10; c=temp/10; } } c=0; a=m-n+1; for(int j=1;j<=maxn-1;j++) { temp=f[j]*a+c; f[j]=temp%10; c=temp/10; } c=0; a=m+1; len=maxn-1; while(f[len]==0) len--; for(int i=len;i>=1;i--) { temp=c+f[i]; f[i]=temp/a; c=(temp%a)*10; } cout<<"Test #"<<t<<":"<<endl; len=maxn-1; while(f[len]==0) len--; for(int i=len;i>=1;i--) cout<<f[i]; cout<<endl; } return 0; }
总结该题应用的思路和特别,首先整体上使用了排除法的思路,将不合法的除去剩下的就是合法的了,具体的解析见点击打开链接,在该题中我们还练习了大数/小数且结果是正数的高精度除法
相关文章推荐
- 多态的使用和向上向下转型
- 3.1.4 全扫描与高水位线
- 3.1.3 全扫描与多块读取
- MP3文件结构及解码概述
- java.lang.IllegalArgumentException: Page directive: invalid value for import 问题处理
- POJ 2312:Battle City【BFS & 优先队列】
- 3.1.2 全扫描与舍弃
- 华为机试题:密码验证合格程序
- android canvas博客详解
- 3.1.1 如何选择全扫描操作
- 通用记忆函数
- Light OJ 1032 Fast Bit Calculations(数位DP)
- iOS 推荐标签_长度不等_collection布局
- Android优化adapter及SparseArray介绍
- Ubuntu 14.04 安装 Sublime Text 3
- 《Head First 设计模式》学习笔记——模板方法模式
- Oracle 数据库 INTERVAL DAY TO SECOND类型的使用
- 跨境电商发展趋势分析
- Win8.1系统使用键盘快捷键浏览网页的方法
- 2.14 小结