链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2048


先看个概率论的题目:

  

HDOJ2048_神、上帝以及老天爷_n的阶乘

HDOJ2048_神、上帝以及老天爷_java_02



import java.util.Scanner;
/**
* 没有一个人中奖 的百分比
* 这个题目知道一个公式就好做了:
* 1/2!-1/3!+1/4!-1/5!.....
* @author 15292
*
*/
public class P2048AA {
private static Scanner scanner;
public static void main(String[] args) {
scanner = new Scanner(System.in);
while(scanner.hasNext()){
int n = scanner.nextInt();
while(n-->0){
int i = scanner.nextInt();
double s = 0;
int flag = 0;
for (int j = 2; j <= i; j++) {
if(flag == 0){
s = s + 1.0/fun(j);
flag = 1;
}else {
s = s - 1.0/fun(j);
flag = 0;
}
}
System.out.printf("%.2f",s*100);
System.out.println("%");
}
}
}
//求n的阶乘
public static long fun(int n){
long a = 1L;
for (int i = 1; i <= n; i++) {
a *= i;
}
return a;
}
}