結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー soujikisoujiki
提出日時 2015-06-23 21:37:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 163 ms / 5,000 ms
コード長 2,939 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 85,544 KB
実行使用メモリ 42,464 KB
最終ジャッジ日時 2024-04-26 22:13:45
合計ジャッジ時間 6,976 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
41,736 KB
testcase_01 AC 112 ms
39,800 KB
testcase_02 AC 151 ms
42,464 KB
testcase_03 AC 150 ms
42,088 KB
testcase_04 AC 126 ms
41,256 KB
testcase_05 AC 131 ms
41,332 KB
testcase_06 AC 125 ms
41,328 KB
testcase_07 AC 115 ms
40,172 KB
testcase_08 AC 113 ms
40,076 KB
testcase_09 AC 128 ms
41,028 KB
testcase_10 AC 123 ms
41,340 KB
testcase_11 AC 154 ms
42,332 KB
testcase_12 AC 126 ms
41,224 KB
testcase_13 AC 152 ms
42,300 KB
testcase_14 AC 139 ms
42,048 KB
testcase_15 AC 127 ms
40,956 KB
testcase_16 AC 152 ms
42,384 KB
testcase_17 AC 129 ms
41,616 KB
testcase_18 AC 156 ms
42,440 KB
testcase_19 AC 133 ms
41,380 KB
testcase_20 AC 154 ms
42,172 KB
testcase_21 AC 163 ms
42,272 KB
testcase_22 AC 162 ms
42,304 KB
testcase_23 AC 158 ms
42,364 KB
testcase_24 AC 155 ms
42,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.awt.geom.*;
import static java.util.Arrays.*;

class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int[] x = new int[4];
		int[] y = new int[4];
		double[] length = new double[4];
		double l = 0;
		int n = 0;
		boolean flag = false;
		for(int i=0;i<3;i++){
			x[i] = Integer.parseInt(stdIn.next());
			y[i] = Integer.parseInt(stdIn.next());
		}
		for(int i=0;i<3;i++){
			length[i] = Math.sqrt(Math.pow(x[i] - x[(i+1)%3],2)+Math.pow(y[i]-y[(i+1)%3],2));
		}
		for(int i=0;i<3;i++){
			if(length[i]==length[(i+1)%3]){
				n = (i+1)%3;
				flag = true;
			}
		}
		Vector v1 = new Vector(x[n],y[n],x[(n+1)%3],y[(n+1)%3]);
		Vector v2 = new Vector(x[n],y[n],x[(n+2)%3],y[(n+2)%3]);
		if(flag && v1.dot(v2)==0){
			v1.add(v2);
			out.println((int)(x[n]+v1.x)+" "+(int)(y[n]+v1.y));
			out.flush();
			return;

		}
		
		out.println(-1);
		out.flush(); 
	}
}

class Vector{
	public final double EPS = Math.pow(10,-8);
	public double x,y;

	Vector( double x1 , double y1 , double x2 , double y2 ){
		this.x = x2 - x1;
		this.y = y2 - y1;
	}

	double dot( Vector a ){	
		return this.x * a.x + this.y * a.y;
	}
	double cross( Vector a ){	
		return this.x * a.y - this.y * a.x;
	}

	void add( Vector a ){
		this.x += a.x;
		this.y += a.y;
	}
	void sub( Vector a ){
		this.x -= a.x;
		this.y -= a.y;
	}
	void mul( double z ){
		this.x *= z;
		this.y *= z;
	}
	void div( double z ){
		this.x /= z;
		this.y /= z;
	}

	double abs(){
		return Math.sqrt(norm());
	}
	double norm(){
		return this.x * this.x + this.y * this.y;
	}

	double cos(Vector a){
		Vector b = new Vector(0,0,this.x,this.y);
		Vector c = new Vector(a.x,a.y,b.x,b.y);
		if(judge(a.dot(b))){
			return 0.0;
		}
		double cos = (Math.pow(a.abs(),2)+Math.pow(b.abs(),2)-Math.pow(c.abs(),2))/(2*a.abs()*b.abs());
		return cos;
	}
	double sin(Vector a){
		Vector b = new Vector(0,0,this.x,this.y);
		if(judge(a.cross(b))){
			return 0.0;
		}
		double height = a.cross(b)/a.abs();
		double sin = b.abs()/height;
		return sin;
	}
	double cosLength( double a , double b , double c ){
		double cos = (Math.pow(a,2) + Math.pow(b,2) - Math.pow(c,2))/(2 * a * b);
		if(judge(cos)){
			return 0.0;
		}
		return cos;
	}
	double sinLength( double a , double b , double c ){
		double cos = cosLength(a,b,c);
		if(judge(1-cos)){
			return 0.0;
		}
		return Math.sqrt(1-Math.pow(cos,2));

	}

	void projection( Vector a ){
		double cos = dot(a)/(abs() * a.abs());
		double frac = a.abs() * cos/abs();
		mul(frac);
	}
	Vector reflection( Vector a ){
		projection(a);
		return new Vector(a.x,a.y,this.x,this.y);
	}

	boolean judgeisOrthogonal( Vector a ){	
		return judge(dot(a)) ? true : false;
	}  
	boolean judgeisParallel( Vector a ){	
		return judge(cross(a)) ? true : false;
	}

	boolean judge( double a ){	
		return Math.abs(a)<EPS ? true : false;
	}
} 
0