結果

問題 No.53 悪の漸化式
ユーザー uafr_csuafr_cs
提出日時 2015-09-15 10:31:39
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 2,460 ms
コンパイル使用メモリ 75,936 KB
実行使用メモリ 58,312 KB
最終ジャッジ日時 2023-09-26 12:02:07
合計ジャッジ時間 6,314 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
56,304 KB
testcase_01 AC 131 ms
56,256 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		BigDecimal A0 = BigDecimal.valueOf(4.0);
		BigDecimal A1 = BigDecimal.valueOf(4.0);
		
		final BigDecimal nineteen = BigDecimal.valueOf(19);
		final BigDecimal twelve = BigDecimal.valueOf(12);
		final BigDecimal four = BigDecimal.valueOf(4);
		
		for(int i = 0; i < N - 1; i++){			
			final BigDecimal value = A0.multiply(nineteen).subtract(A1.multiply(twelve)).divide(four);
			
			A0 = A1; A1 = value;
		}
		
		if(N == 0){
			System.out.printf("%.12f\n", 4.0);
		}else if(N == 1){
			System.out.printf("%.12f\n", 3.0);
		}else{
			System.out.printf("%.12f\n", A1);
		}
	}

}
0