• 문제 링크
https://www.acmicpc.net/problem/5205
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int t = read();
for (int tc = 1; tc <= t; tc++) {
int[][] mat = new int[read()][3];
for (int i = 0; i < mat.length; i++) mat[i] = new int[]{read(), read(), read()};
List<Data> list = new ArrayList<>();
int max = 0;
for (int i = 0; i < mat.length; i++) {
for (int j = i + 1; j < mat.length; j++) {
int k = calc(mat[i], mat[j]);
if (max < k) {
max = k;
list.clear();
list.add(new Data(i, j, k));
} else if (max == k) list.add(new Data(i, j, k));
}
}
sb.append("Data Set ").append(tc).append(":\n");
for (Data d : list) sb.append(d.x + 1).append(' ').append(d.y + 1).append('\n');
}
bw.write(sb.toString());
bw.flush();
}
private static int calc(int[] a, int[] b) {
return (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]);
}
private static class Data {
int x, y, z;
Data(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}'Problem Solving > Baekjoon' 카테고리의 다른 글
| [백준] 6815 Cool Numbers - Brute Force / Java (0) | 2025.11.14 |
|---|---|
| [백준] 19741 Patterns - Brute Force / Java (0) | 2025.11.13 |
| [백준] 34723 피막치 - Brute Force / Java (0) | 2025.11.11 |
| [백준] 19532 수학은 비대면강의입니다 - Brute Force / Java (0) | 2025.11.10 |
| [백준] 30580 Natatorium - Data Structure / Java (0) | 2025.11.09 |
댓글