JAVA HDU 2048 神、上帝以及老天爷

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2048

一开始用的System.out.printf("%.2f%%\n", result)输出,PRESENTATION ERROR.  换成System.out.println(String.format("%.2f", result)+"%")就好了

 1 package hdu;
 2 
 3 import java.io.BufferedInputStream;
 4 import java.util.Scanner;
 5 
 6 public class hdu_2048 {
 7     public static void main(String[] args) {
 8         Scanner in = new Scanner(new BufferedInputStream(System.in));
 9         long fact[] = new long[21];
10         fact[1] = 1;
11         for (int i = 2; i < fact.length; i++) {
12             fact[i] = fact[i-1] *i;
13         }
14         long f[] = new long[21];
15         f[2] = 1;
16         f[3] = 2;
17         for (int i = 4; i < 21; i++) {
18             f[i] = (i-1) * (f[i-1] + f[i-2] );
19         }
20         int T = in.nextInt();
21         while(T-- >0) {
22             int n = in.nextInt();
23             double result = f[n]*1.0/(fact[n]*1.0)*100;
24             System.out.println(String.format("%.2f", result)+"%");
25 } 26 } 27 }

 

JAVA HDU 2048 神、上帝以及老天爷,布布扣,bubuko.com

JAVA HDU 2048 神、上帝以及老天爷

上一篇:elasticsearch篇之mapping


下一篇:Java 反编译工具 —— JAD 的下载地址(Windows版/Linux版/Mac OS 版)