您的位置:首页 > 其它

HDOJ 1133 Buy the Ticket

2015-01-20 10:10 357 查看
题意:有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 IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor
127425592015-01-20 10:09:55Accepted1133312MS9744K823 BJavaluminous11
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);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: