• hdu 1133 Buy the Ticket(Catalan)


    Buy the Ticket

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 5651    Accepted Submission(s): 2357

    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
    3 0 3 1 3 3 0 0
     
    Sample Output
    Test #1: 6 Test #2: 18 Test #3: 180
     
    Author
    HUANG, Ninghai

    题意:

    m個人拿50n個人拿100,而且售票处没有零钱。求这排人最终能够能全买到票的方案数

    (如果没有50零钱找给拿一百的人则停)。


    思路:

    排列的所有可能情况:C(n+m,m)

    假设一个数列 0110010当买到第三个人的时候便停止了,将后面的数1->0,0->1便能得到 0111101

    反之亦然,于是我们可以得出他们是一一对应的。


    于是我们用所有可能减去不成立的

    (C(n+m,m) - C(n+m,m+1))*m!*n! = (n+m)! * (m-n+1) / (m+1); 

    然后再利用JAVA的大整数即可 


    import java.math.BigInteger;
    import java.util.Scanner;
    
    public class Main {
    
    	static BigInteger []F =  new BigInteger[105];
    	static BigInteger []A =  new BigInteger[205];
    	public static void ini()
    	{
    		F[1] = BigInteger.valueOf(1);
    		A[1] = BigInteger.valueOf(1);
    		A[0] = BigInteger.valueOf(0);
    		F[0] = F[1];
    		for(int i = 2;i < 105;i++)
    		{
    			F[i] = F[i-1].multiply(BigInteger.valueOf(i*4-2)).divide(BigInteger.valueOf(i+1));
    		}
    		for(int i = 2;i <= 203;i++)
    		{
    			A[i] = A[i-1].multiply(BigInteger.valueOf(i));
    		}
    	}
    	public static void main(String[] args) {
    		// TODO 自动生成的方法存根
    		ini();
    		Scanner Reader = new Scanner(System.in);
    		int x,y;
    		int cas = 1;
    		BigInteger ans;
    		while(true)
    		{
    			x = Reader.nextInt();
    			y = Reader.nextInt();
    			
    			if(x == 0 && y == 0)
    				break;
    			System.out.println("Test #"+cas+":");
    			cas++;
    			if(x < y){
    				System.out.println("0");
    			}
    			else
    			{
    			  int t = x+y;
    			  ans = A[t].multiply(BigInteger.valueOf(x-y+1)).divide(BigInteger.valueOf(x+1));
    						  System.out.println(ans);
    			}
    		}     
    	}
    
    }
    

      

  • 相关阅读:
    PMP笔记:行政收尾工作
    PMP 笔记:WBS 词典 (含范例)
    PMP 笔记:WBS 实战 (例子)
    名义小组和德尔菲技术使用与区别
    焦点小组、名义小组和引导式会议的定义与区别
    工作分解结构WBS、组织分解结构OBS、资源分解结构 定义和区别(含例子)
    kettle里的参数和变量
    kettle生成100个随机数,并统计小于等于50和大于50个数
    使用kettle制作拉链表
    MySQL字符串转日期
  • 原文地址:https://www.cnblogs.com/Przz/p/5409660.html
Copyright © 2020-2023  润新知