码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-07-26 17:02:31      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   io   for   div   

题目地址: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 神、上帝以及老天爷

标签:style   blog   http   java   color   io   for   div   

原文地址:http://www.cnblogs.com/DAXS/p/3870180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!