• 문제 링크
https://www.acmicpc.net/problem/27445
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
static Node[] arr;
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), m = read();
arr = new Node[n + m - 1];
int i = 0;
for (int j = 1; j <= n; j++) arr[i++] = new Node(j, 1, read());
for (int j = 2; j <= m; j++) arr[i++] = new Node(n, j, read());
bw.write(search(n, m));
bw.flush();
}
private static String search(int n, int m) {
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (measure(i, j)) return i + " " + j;
return "";
}
private static boolean measure(int y, int x) {
for (Node n : arr) if (Math.abs(n.y - y) + Math.abs(n.x - x) != n.w) return false;
return true;
}
private static class Node {
int y, x, w;
Node(int y, int x, int w) {
this.y = y;
this.x = x;
this.w = w;
}
}
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' 카테고리의 다른 글
[백준] 30189 경우의 수의 합 - Brute Force / Java (0) | 2024.07.05 |
---|---|
[백준] 15995 잉여역수 구하기 - Brute Force / Java (0) | 2024.07.04 |
[백준] 1205 등수 구하기 - Implementation / Java (0) | 2024.07.02 |
[백준] 1769 3의 배수 - Implementation / Java (0) | 2024.07.01 |
[백준] 11576 Base Conversion - Implementation / Java (0) | 2024.06.30 |
댓글