結果

問題 No.471 直列回転機
ユーザー uwiuwi
提出日時 2016-12-21 00:12:05
言語 Java19
(openjdk 21)
結果
AC  
実行時間 816 ms / 3,141 ms
コード長 3,488 bytes
コンパイル時間 5,537 ms
コンパイル使用メモリ 77,112 KB
実行使用メモリ 83,980 KB
平均クエリ数 19589.39
最終ジャッジ日時 2023-09-02 03:38:01
合計ジャッジ時間 38,204 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 174 ms
72,236 KB
testcase_01 AC 169 ms
72,872 KB
testcase_02 AC 164 ms
72,636 KB
testcase_03 AC 165 ms
72,456 KB
testcase_04 AC 174 ms
72,652 KB
testcase_05 AC 230 ms
72,360 KB
testcase_06 AC 183 ms
71,912 KB
testcase_07 AC 221 ms
72,696 KB
testcase_08 AC 342 ms
77,280 KB
testcase_09 AC 356 ms
77,196 KB
testcase_10 AC 303 ms
77,076 KB
testcase_11 AC 527 ms
75,200 KB
testcase_12 AC 739 ms
82,668 KB
testcase_13 AC 729 ms
82,008 KB
testcase_14 AC 769 ms
82,656 KB
testcase_15 AC 816 ms
83,980 KB
testcase_16 AC 196 ms
72,140 KB
testcase_17 AC 169 ms
70,664 KB
testcase_18 AC 170 ms
72,416 KB
testcase_19 AC 168 ms
72,656 KB
testcase_20 AC 775 ms
82,696 KB
testcase_21 AC 409 ms
77,168 KB
testcase_22 AC 739 ms
82,044 KB
testcase_23 AC 717 ms
82,480 KB
testcase_24 AC 560 ms
77,300 KB
testcase_25 AC 376 ms
77,364 KB
testcase_26 AC 758 ms
83,664 KB
testcase_27 AC 548 ms
76,412 KB
testcase_28 AC 592 ms
77,048 KB
testcase_29 AC 626 ms
75,592 KB
testcase_30 AC 446 ms
77,468 KB
testcase_31 AC 782 ms
83,192 KB
testcase_32 AC 719 ms
78,900 KB
testcase_33 AC 650 ms
78,272 KB
testcase_34 AC 755 ms
80,920 KB
testcase_35 AC 415 ms
75,768 KB
testcase_36 AC 529 ms
77,720 KB
testcase_37 AC 338 ms
77,268 KB
testcase_38 AC 397 ms
77,672 KB
testcase_39 AC 487 ms
76,892 KB
testcase_40 AC 665 ms
78,032 KB
testcase_41 AC 784 ms
82,204 KB
testcase_42 AC 633 ms
77,276 KB
testcase_43 AC 752 ms
81,928 KB
testcase_44 AC 308 ms
77,904 KB
testcase_45 AC 626 ms
77,668 KB
testcase_46 AC 659 ms
77,856 KB
testcase_47 AC 757 ms
82,416 KB
testcase_48 AC 714 ms
81,204 KB
testcase_49 AC 695 ms
80,540 KB
testcase_50 AC 730 ms
82,296 KB
testcase_51 AC 509 ms
76,800 KB
testcase_52 AC 227 ms
70,940 KB
testcase_53 AC 198 ms
72,040 KB
testcase_54 AC 240 ms
72,308 KB
testcase_55 AC 428 ms
77,400 KB
testcase_56 AC 396 ms
77,508 KB
testcase_57 AC 337 ms
76,984 KB
testcase_58 AC 312 ms
75,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package adv2016;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class N471 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static long[] get(long x, long y)
	{
		out.println("? " + x + " " + y);
		out.flush();
		return new long[]{nl(), nl()};
	}
	
	static void solve()
	{
		int m = ni();
		double[][] rotr = new double[m][];
		for(int i = 0;i < m;i++){
			rotr[i] = new double[]{ni(), ni(), 1};
		}
		Random gen = new Random();
		long[][] res = new long[3][];
		long[] xs = new long[3];
		long[] ys = new long[3];
		for(int i = 0;i < 3;i++){
			xs[i] = gen.nextInt(100)-50;
			ys[i] = gen.nextInt(100)-50;
			res[i] = get(xs[i], ys[i]);
			// ax+by+c=x'
		}
		double[][] X = new double[3][];
		{
			double[][] M = new double[3][3];
			double[] v = new double[3];
			for(int i = 0;i < 3;i++){
				M[i][0] = xs[i];
				M[i][1] = ys[i];
				M[i][2] = 1;
				v[i] = res[i][0];
			}
			double[] ret = solve(M, v);
			X[0] = ret;
		}
		{
			double[][] M = new double[3][3];
			double[] v = new double[3];
			for(int i = 0;i < 3;i++){
				M[i][0] = xs[i];
				M[i][1] = ys[i];
				M[i][2] = 1;
				v[i] = res[i][1];
			}
			double[] ret = solve(M, v);
			X[1] = ret;
		}
		{
			double[][] M = new double[3][3];
			double[] v = new double[3];
			for(int i = 0;i < 3;i++){
				M[i][0] = xs[i];
				M[i][1] = ys[i];
				M[i][2] = 1;
				v[i] = 1;
			}
			double[] ret = solve(M, v);
			X[2] = ret;
		}
		
		// (a b c) (x)
		// (d e f) (y)
		// (g h i) (1)
		
		out.println("!");
		for(int i = 0;i < m;i++){
			double[] w = mul(X, rotr[i]);
			out.println(Math.round(w[0]) + " " + Math.round(w[1]));
		}
	}
	
	public static double[] mul(double[][] A, double[] v)
	{
		int m = A.length;
		int n = v.length;
		double[] w = new double[m];
		for(int i = 0;i < m;i++){
			double sum = 0;
			for(int k = 0;k < n;k++){
				sum += A[i][k] * v[k];
			}
			w[i] = sum;
		}
		return w;
	}
	
	public static double[] solve(double[][] a, double[] c)
	{
		int n = a.length;
		int[] ps = new int[n];
		for(int i = 0;i < n;i++)ps[i] = i;
		
		// Forward Elimination
		for(int i = 0;i < n;i++){
			int pivot = -1;
			int from = -1;
			double amax = 0;
			for(int j = i;j < n;j++){
				if(Math.abs(a[ps[j]][i]) > amax){
					amax = Math.abs(a[ps[j]][i]);
					pivot = ps[j];
					from = j;
				}
			}
			if(pivot == -1)return null;
			int d = ps[i]; ps[i] = ps[from]; ps[from] = d;
			
			for(int j = i+1;j < n;j++){
				a[ps[i]][j] /= a[ps[i]][i];
			}
			c[ps[i]] /= a[ps[i]][i];
			a[ps[i]][i] = 1.0;
			for(int j = i+1;j < n;j++){
				for(int k = i+1;k < n;k++){
					a[ps[j]][k] -= a[ps[j]][i] * a[ps[i]][k];
				}
				c[ps[j]] -= a[ps[j]][i] * c[ps[i]];
				a[ps[j]][i] = 0.0;
			}
			
		}
		
		// Back Substitution
		for(int i = n-1;i >= 0;i--){
			for(int j = i-1;j >= 0;j--){
				c[ps[j]] -= a[ps[j]][i] * c[ps[i]];
			}
		}
		
		double[] ret = new double[n];
		for(int i = 0;i < n;i++){
			ret[i] = c[ps[i]];
		}
		
		return ret;
	}

	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0