hdoj Buy the Ticket 1133 (排列组合题)
来源:互联网 发布:firefox linux 安装 编辑:程序博客网 时间:2024/05/21 03:26
Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5668 Accepted Submission(s): 2360
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//题意:要去买票,每张票50元,但买票商没有多余的零钱。现在问有n个人是50元,m个人是100元,问总共有几种排列方式。//思路:转换:也就是从左往右遍历,并且50元的个数总大于等于100的个数,只有这样才符合要求。先找出符合要求的排列,也就是在m+n个空中最多填n个100,及C(n+m,n)再找出不符合要求的,也就是在m+n个空中填m+1个100,及C(n+m,m+1)所以共有( C(m+n, n) - C(m+n, m+1) ) * m! * n! 化简即 (m+n)! * (m-n+1) / (m+1) 种情况。#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;int a[1001];void dsx(int n){int c=0,i;for(i=0;i<=10000;i++){c=a[i]*n+c;a[i]=c%10;c/=10;}}void dsz(int n){int c=0,i;for(i=10000;i>=0;i--){c=a[i]+c*10;a[i]=c/n;c%=n;}}int main(){int n,m,s,i,j,T=1;while(scanf("%d%d",&n,&m),n|m){if(n<m)printf("Test #%d:\n0\n",T++);else{memset(a,0,sizeof(a));a[0]=1;s=n+m;for(i=1;i<=s;i++)dsx(i);dsx(n-m+1);dsz(n+1);for(i=10000;i>=0;i--)if(a[i])break;printf("Test #%d:\n",T++);for(j=i;j>=0;j--)printf("%d",a[j]);printf("\n");}}}
0 0
- hdoj Buy the Ticket 1133 (排列组合题)
- HDOJ 1133 Buy the Ticket
- hdoj Buy the Ticket
- HDOJ 题目1133Buy the Ticket(大数,数学)
- hdoj 1133 Buy the Ticket 【卡特兰】
- HDOJ HDU 1133 Buy the Ticket
- 1133-Buy the Ticket
- hdoj 1133 Buy the Ticket 【DP】【java】【水】
- HDOJ 1133 Buy the Ticket(高精度卡特兰数变形)
- HDU 1133 Buy the Ticket(DP)
- hdu 1133 Buy the Ticket(Catalan)
- hdu 1133 Buy the Ticket (dp)
- HDOJ_ 1133 Buy the Ticket
- HDOJ_ 1133 Buy the Ticket
- hdu 1133 Buy the Ticket
- buy the ticket hdu 1133
- HDU 1133 Buy the Ticket
- hdu 1133 Buy the Ticket
- 为什么年轻人挣得很多还是穷?北上广深挑战指数报告~
- java--equal同==的区别
- Ubuntu12.04下 降低gcc版本的方法
- Linux 复制文件夹命令
- Authorization code grant 和 Implicit grant 有什么区别?
- hdoj Buy the Ticket 1133 (排列组合题)
- 数据结构与算法——迭代打开url问题(链表)
- Oracle 报错全记录
- java--foreach语句
- jquery源码学习1
- 圣诞新年送豪礼《远征》双蛋运动开启--国民网游戏
- 关于js的吐槽
- (java)Add Binary
- 解决TinyOS-2.1.1下make: python2.5-config: Command not found 的错误