結果

問題 No.620 ぐるぐるぐるりん
ユーザー 37zigen37zigen
提出日時 2017-12-25 02:02:53
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,904 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 77,032 KB
実行使用メモリ 69,132 KB
最終ジャッジ日時 2023-09-03 21:30:53
合計ジャッジ時間 12,210 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
57,324 KB
testcase_01 AC 177 ms
57,184 KB
testcase_02 AC 186 ms
57,056 KB
testcase_03 AC 181 ms
57,292 KB
testcase_04 AC 177 ms
56,892 KB
testcase_05 AC 179 ms
56,784 KB
testcase_06 AC 169 ms
57,496 KB
testcase_07 AC 174 ms
56,912 KB
testcase_08 AC 176 ms
57,120 KB
testcase_09 AC 178 ms
57,232 KB
testcase_10 AC 176 ms
56,992 KB
testcase_11 AC 178 ms
57,156 KB
testcase_12 AC 175 ms
56,980 KB
testcase_13 AC 177 ms
57,112 KB
testcase_14 AC 176 ms
58,912 KB
testcase_15 AC 175 ms
57,108 KB
testcase_16 AC 176 ms
56,948 KB
testcase_17 AC 175 ms
56,800 KB
testcase_18 AC 169 ms
57,292 KB
testcase_19 AC 176 ms
56,760 KB
testcase_20 AC 170 ms
59,072 KB
testcase_21 AC 175 ms
57,156 KB
testcase_22 AC 176 ms
59,164 KB
testcase_23 AC 178 ms
56,844 KB
testcase_24 AC 176 ms
57,324 KB
testcase_25 AC 169 ms
57,108 KB
testcase_26 AC 672 ms
63,568 KB
testcase_27 AC 173 ms
57,132 KB
testcase_28 AC 671 ms
63,360 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