結果

問題 No.620 ぐるぐるぐるりん
ユーザー 37zigen37zigen
提出日時 2020-05-11 18:23:54
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,022 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 76,908 KB
実行使用メモリ 69,716 KB
最終ジャッジ日時 2023-09-25 21:09:24
合計ジャッジ時間 16,239 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
57,020 KB
testcase_01 AC 199 ms
57,620 KB
testcase_02 AC 225 ms
58,500 KB
testcase_03 AC 181 ms
56,960 KB
testcase_04 AC 178 ms
57,476 KB
testcase_05 AC 179 ms
57,156 KB
testcase_06 AC 177 ms
57,392 KB
testcase_07 AC 176 ms
57,224 KB
testcase_08 AC 211 ms
59,228 KB
testcase_09 AC 208 ms
57,440 KB
testcase_10 AC 196 ms
57,628 KB
testcase_11 AC 195 ms
57,492 KB
testcase_12 AC 192 ms
57,360 KB
testcase_13 AC 199 ms
58,340 KB
testcase_14 AC 200 ms
55,412 KB
testcase_15 AC 199 ms
57,356 KB
testcase_16 AC 187 ms
57,416 KB
testcase_17 AC 178 ms
56,980 KB
testcase_18 AC 194 ms
57,404 KB
testcase_19 AC 202 ms
57,728 KB
testcase_20 AC 183 ms
57,340 KB
testcase_21 AC 191 ms
57,540 KB
testcase_22 AC 193 ms
57,388 KB
testcase_23 AC 201 ms
57,224 KB
testcase_24 AC 170 ms
57,068 KB
testcase_25 AC 171 ms
57,448 KB
testcase_26 TLE -
testcase_27 AC 170 ms
57,480 KB
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
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) {
				BigDecimal sum=new BigDecimal(0);
				for (int k = 0; k < a[i].length; ++k) {
					sum=sum.add(BigDecimal.valueOf(a[i][k]*b[k][j]));
				}
				ret[i][j]=sum.doubleValue();
			}
		}
		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