알고리즘

5일차 실버5 1064 평행사변형

비루블 2023. 2. 1. 00:48

https://www.acmicpc.net/problem/1064

 

1064번: 평행사변형

평행사변형은 평행한 두 변을 가진 사각형이다. 세 개의 서로 다른 점이 주어진다. A(xA,yA), B(xB,yB), C(xC,yC) 이때, 적절히 점 D를 찾아서 네 점으로 평행사변형을 만들면 된다. 이때, D가 여러 개 나

www.acmicpc.net

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

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double[] point = new double[6];
        for(int i = 0; i < 6; i++){
            point[i] = in.nextDouble();
        }
        double[] pointlen = new double[3];
        pointlen[0] = Math.sqrt(Math.pow((point[0]-point[2]),2)+Math.pow((point[1])-point[3],2));
        pointlen[1] = Math.sqrt(Math.pow((point[0]-point[4]),2)+Math.pow((point[1])-point[5],2));
        pointlen[2] = Math.sqrt(Math.pow((point[2]-point[4]),2)+Math.pow((point[3])-point[5],2));
        double maxlen = Math.max(Math.max(pointlen[0], pointlen[1]), pointlen[2]);
        double minlen = Math.min(Math.min(pointlen[0], pointlen[1]), pointlen[2]);
        if(point[0] == point[2] && point[2] == point[4]){
            System.out.println("-1.0");
        }
        else if(point[1] == point[3] && point[3] == point[5]){
            System.out.println("-1.0");
        }
        else if(((point[3]-point[1])/(point[2]-point[0])) == (point[5]-point[3])/(point[4]-point[2])){
            System.out.println("-1.0");
        }
        else{
            System.out.println(maxlen*2-minlen*2);
        }
    }
}

딱 1시간 소요

수학적 머리가 굳어버려서 공식 찾느라 애먹음.

세점이 같은 선상에 있을경우 -1 출력(기울기 포함)