結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー ぴろずぴろず
提出日時 2014-12-12 11:42:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 228 ms / 5,000 ms
コード長 1,542 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 81,948 KB
実行使用メモリ 46,424 KB
最終ジャッジ日時 2024-04-26 22:10:54
合計ジャッジ時間 8,871 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 193 ms
45,832 KB
testcase_01 AC 210 ms
45,552 KB
testcase_02 AC 206 ms
46,300 KB
testcase_03 AC 218 ms
46,176 KB
testcase_04 AC 207 ms
45,392 KB
testcase_05 AC 214 ms
45,404 KB
testcase_06 AC 206 ms
45,264 KB
testcase_07 AC 208 ms
45,748 KB
testcase_08 AC 203 ms
45,112 KB
testcase_09 AC 211 ms
45,396 KB
testcase_10 AC 199 ms
45,448 KB
testcase_11 AC 201 ms
45,856 KB
testcase_12 AC 207 ms
45,460 KB
testcase_13 AC 227 ms
46,336 KB
testcase_14 AC 184 ms
46,424 KB
testcase_15 AC 194 ms
45,556 KB
testcase_16 AC 198 ms
46,068 KB
testcase_17 AC 211 ms
45,572 KB
testcase_18 AC 213 ms
46,308 KB
testcase_19 AC 200 ms
45,116 KB
testcase_20 AC 193 ms
46,340 KB
testcase_21 AC 177 ms
46,028 KB
testcase_22 AC 228 ms
46,396 KB
testcase_23 AC 208 ms
46,136 KB
testcase_24 AC 195 ms
46,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no055;

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Vector2[] v = new Vector2[4];
		for(int i=0;i<3;i++) {
			v[i] = new Vector2(sc.nextInt(),sc.nextInt());
		}
		for(int x=-200;x<=200;x++) {
			for(int y=-200;y<=200;y++) {
				v[3] = new Vector2(x,y);
				if (isSquare(v)) {
					System.out.println(v[3]);
					return;
				}
			}
		}
		System.out.println(-1);
	}

	public static boolean isSquare(Vector2[] v) {
		long[] l = new long[6];
		int ind = 0;
		for(int i=0;i<4;i++) {
			for(int j=i+1;j<4;j++) {
				l[ind++] = v[i].distSquare(v[j]);
			}
		}
		Arrays.sort(l);
		long a = l[0];
		return l[1] == a && l[2] == a && l[3] == a && l[4] == a * 2 && l[5] == a * 2;
	}

}
class Vector2 {
	int x = 0;
	int y = 0;
	public Vector2(int x,int y) {
		this.x = x;
		this.y = y;
	}
	public int dot(Vector2 v) {
		return this.x*v.x+this.y*v.y;
	}
	public int cross(Vector2 v) {
		return this.x*v.y-this.y*v.x;
	}
	public Vector2 add(Vector2 v) {
		return new Vector2(this.x+v.x,this.y+v.y);
	}
	public Vector2 subtract(Vector2 v) {
		return new Vector2(this.x-v.x,this.y-v.y);
	}
	public Vector2 multiply(int k) {
		return new Vector2(k*this.x,k*this.y);
	}
	public long normSquare() {
		return x * x + y * y;
	}
	public long distSquare(Vector2 v) {
		return this.subtract(v).normSquare();
	}
	public String toString() {
		return this.x + " " + this.y;
	}
}
0