結果

問題 No.620 ぐるぐるぐるりん
ユーザー 37zigen37zigen
提出日時 2020-05-11 18:20:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,904 bytes
コンパイル時間 2,427 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 66,576 KB
最終ジャッジ日時 2023-09-25 20:56:59
合計ジャッジ時間 12,923 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
54,732 KB
testcase_01 AC 169 ms
56,988 KB
testcase_02 AC 176 ms
57,308 KB
testcase_03 AC 173 ms
56,908 KB
testcase_04 AC 169 ms
56,740 KB
testcase_05 AC 164 ms
57,028 KB
testcase_06 AC 163 ms
56,992 KB
testcase_07 AC 168 ms
56,904 KB
testcase_08 AC 168 ms
57,220 KB
testcase_09 AC 165 ms
56,812 KB
testcase_10 AC 166 ms
57,200 KB
testcase_11 AC 165 ms
57,256 KB
testcase_12 AC 167 ms
57,188 KB
testcase_13 AC 169 ms
57,216 KB
testcase_14 AC 164 ms
56,940 KB
testcase_15 AC 167 ms
57,240 KB
testcase_16 AC 167 ms
57,080 KB
testcase_17 AC 167 ms
59,304 KB
testcase_18 AC 179 ms
56,692 KB
testcase_19 AC 173 ms
57,168 KB
testcase_20 AC 170 ms
57,224 KB
testcase_21 AC 169 ms
57,036 KB
testcase_22 AC 165 ms
59,108 KB
testcase_23 AC 166 ms
57,156 KB
testcase_24 AC 165 ms
56,996 KB
testcase_25 AC 165 ms
56,864 KB
testcase_26 AC 636 ms
64,292 KB
testcase_27 AC 169 ms
57,016 KB
testcase_28 AC 655 ms
65,636 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

class Main {

	double pow(double a, int n) {
		double ret = 1;
		for (; n > 0; n >>= 1, a = a * a) {
			if (n % 2 == 1) {
				ret = ret * a;
			}
		}
		return ret;
	}

	double[][] pow(double[][] a, int n) {
		double[][] ret = new double[a.length][a.length];
		for (int i = 0; i < ret.length; ++i)
			ret[i][i] = 1;
		for (; n > 0; n >>= 1, a = mul(a, a)) {
			if (n % 2 == 1) {
				ret = mul(ret, a);
			}
		}
		return ret;
	}

	double[][] mul(double[][] a, double[][] b) {
		double[][] ret = new double[a.length][b[0].length];
		for (int i = 0; i < a.length; ++i) {
			for (int j = 0; j < b[i].length; ++j) {
				for (int k = 0; k < a[i].length; ++k) {
					ret[i][j] += a[i][k] * b[k][j];
				}
			}
		}
		return ret;
	}

	void solve(int T, double w, double v, double gx, double gy) {
		double s = Math.sqrt((1 + v) * (1 + v) + w * w);
		double coe = 0;
		for (int i = 0; i <= T - 1; ++i) {
			coe += pow(s, 2 * i);
		}
		coe = 1 / coe;
		double[][] M = { { 1 + v, -w }, { w, 1 + v } };
		double[][] revM = { { 1 + v, w }, { -w, 1 + v } };
		double[][] g = { { gx }, { gy } };
		double[][] src = { { 1 }, { 0 } };
		double[][] h = mul(pow(M, T), src);
		h[0][0] = coe * (g[0][0] - h[0][0]);
		h[1][0] = coe * (g[1][0] - h[1][0]);
		for (int i = 0; i <= T - 1; ++i) {
			double[][] u = mul(pow(revM, T - 1 - i), h);
			System.out.println(u[0][0] + " " + u[1][0]);
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; ++i) {
			int T = sc.nextInt();
			double p = sc.nextDouble();
			double w = sc.nextDouble();
			double v = sc.nextDouble();
			double gx = sc.nextDouble();
			double gy = sc.nextDouble();
			solve(T, w, v, gx, gy);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}
0