結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー |
![]() |
提出日時 | 2014-12-12 11:42:20 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 221 ms / 5,000 ms |
コード長 | 1,542 bytes |
コンパイル時間 | 2,639 ms |
コンパイル使用メモリ | 81,904 KB |
実行使用メモリ | 58,040 KB |
最終ジャッジ日時 | 2024-11-14 13:47:58 |
合計ジャッジ時間 | 8,608 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
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;}}