//움직이는 지렁이
//멈춰있는 지렁이
//A->B=(O->B)-(O->A)=(-2,2)
//B->A=(O->A)-(O->B)=(2-,2)
import java.util.Scanner;
public class Solution_D4_1494_사랑의카운슬러 {
static int T, N;
static long AX, AY, BY, BX;
static boolean[] check;
static Point[] point;
static long min;
static class Point {
long y, x;
Point(int y, int x) {
this.y = y;
this.x = x;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
T = sc.nextInt();
for (int t = 1; t <= T; t++) {
N = sc.nextInt();
check = new boolean[N];
point = new Point[N];
for (int n = 0; n < N; n++) {
point[n] = new Point(sc.nextInt(), sc.nextInt());
}
min = Long.MAX_VALUE;
combi(0, 0);
System.out.println("#" + t + " " + min);
}
}
// combi는 start로 시작
private static void combi(int start, int count) {
if (count == N / 2) {
for (int i = 0; i < N; i++) {
if (check[i] == false) {
BX += point[i].x;
BY += point[i].y;
} else {
AX += point[i].x;
AY += point[i].y;
}
}
long M = (long) ((BX - AX) * (BX - AX) + (BY - AY) * (BY - AY));
min = min > M ? M : min;
BY = 0;
BX = 0;
AY = 0;
AX = 0;
return;
}
for (int i = start; i < N; i++) {
check[i] = true;
combi(i + 1, count + 1);
check[i] = false;
}
}
}
Solving Point
반응형
'코딩가딩가딩 > SW Expert' 카테고리의 다른 글
[SWEA]D2_1859_백만장자프로젝트 (0) | 2020.10.21 |
---|---|
D4_8275_햄스터 (0) | 2020.03.11 |
SWEA 4408 자기 방으로 돌아가기 (0) | 2020.02.20 |
댓글