题意:有m个带50元的人和n个带100元的人,开始时收银台没有钱,每张票卖50,并且结束时没有50元,求有多少种排队的顺序
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133
思路:可以求出公式ans=(m+n)!*(m-n+1)/(m+1)
注意点:唔
以下为AC代码:
Run ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
12742559 | 2015-01-20 10:09:55 | Accepted | 1133 | 312MS | 9744K | 823 B | Java | luminous11 |
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
int ncase = 0;
while ( cin.hasNext() ){
ncase ++;
BigInteger a = new BigInteger("1");
int c = cin.nextInt();
int b = cin.nextInt();
if ( c == 0 && b == 0 ){
break;
}
System.out.printf("Test #%d:%n", ncase);
if ( c < b ){
System.out.println("0");
continue;
}
for ( int i = 1; i <= c+b; i ++ ){
BigInteger tmp = new BigInteger(((Integer)i).toString());
a = a.multiply(tmp);
}
BigInteger tmp = new BigInteger(((Integer)(c-b+1)).toString());
a = a.multiply(tmp);
tmp = new BigInteger(((Integer)(c+1)).toString());
a = a.divide(tmp);
System.out.println(a);
}
}
}