結果

問題 No.53 悪の漸化式
ユーザー ぴろずぴろず
提出日時 2014-12-15 12:50:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 72,660 KB
実行使用メモリ 58,216 KB
最終ジャッジ日時 2023-09-02 14:50:36
合計ジャッジ時間 5,628 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,048 KB
testcase_01 AC 127 ms
57,860 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 AC 130 ms
55,824 KB
testcase_18 AC 135 ms
56,348 KB
testcase_19 AC 135 ms
55,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no053;

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		BigDecimal x0 = new BigDecimal("4");
		BigDecimal x1 = new BigDecimal("3");
		BigDecimal c1 = new BigDecimal("19");
		BigDecimal c2 = new BigDecimal("-12");
		BigDecimal c3 = new BigDecimal("4");
		if (n <= 1) {
			if (n == 0) {
				System.out.println(x0);
			}else{
				System.out.println(x1);
			}
			return;
		}
		BigDecimal x2 = BigDecimal.ZERO;
		for(int i=0;i<n-2;i++) {
//			System.out.println(x2);
			x2 = x1.multiply(c1).add(x0.multiply(c2)).divide(c3);
			x0 = x1;
			x1 = x2;
		}
		if (x2.compareTo(new BigDecimal("1E-9")) <= 0) {
			System.out.println(0);
		}else{
			System.out.println(x2.setScale(10,BigDecimal.ROUND_HALF_EVEN).toPlainString());
		}
	}

}
0