HDOJ 1133 Buy the tickets!
来源:互联网 发布:前台ajax获取json数据 编辑:程序博客网 时间:2024/06/14 07:41
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.
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 03 13 30 0
Sample Output
Test #1:6Test #2:18Test #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;}
总结该题应用的思路和特别,首先整体上使用了排除法的思路,将不合法的除去剩下的就是合法的了,具体的解析见点击打开链接,在该题中我们还练习了大数/小数且结果是正数的高精度除法
0 0
- HDOJ 1133 Buy the tickets!
- HDU's ACM 1133 Buy The Tickets
- HDOJ 1133 Buy the Ticket
- hdoj 1133 Buy the Ticket 【卡特兰】
- HDOJ HDU 1133 Buy the Ticket
- hdoj Buy the Ticket
- Buy Tickets
- Buy Tickets
- Buy Tickets
- Buy Tickets
- Buy Tickets
- Buy Tickets
- Buy Tickets
- Buy Tickets
- 【大数+DP】HDU 1133——Buy the tickets(不用catalan数了)
- hdoj 1133 Buy the Ticket 【DP】【java】【水】
- HDOJ 题目1133Buy the Ticket(大数,数学)
- hdoj Buy the Ticket 1133 (排列组合题)
- 2.7 视图合并
- PL/SQL编程学习之开篇
- hdu4324 Triangle LOVE(拓扑排序)
- 2.8 子查询解嵌套
- java.lang.IllegalArgumentException: Page directive: invalid value for import 问题处理
- HDOJ 1133 Buy the tickets!
- Linux目录结构及文件操作
- 把Python默认编码更换为utf-8
- SDL入门(一)
- 2.11 确定执行计划
- mongodb 从2.4 升级到2.6的数据检验
- linux里的backlog详解
- vijos1514天才的记忆
- View的onMeasure()方法解读