• 문제 링크
18268번: Cow Gymnastics
The consistent pairs of cows are $(1,4)$, $(2,4)$, $(3,4)$, and $(1,3)$.
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int k = read(), n = read(), t = k;
int[] arr = new int[n];
int[][] mat = new int[n][n];
while (t-- > 0) {
for (int i = 0; i < n; i++) arr[i] = read() - 1;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) mat[arr[i]][arr[j]]++;
}
int cnt = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) if (mat[i][j] == k) cnt++;
bw.write(String.valueOf(cnt));
bw.flush();
}
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' 카테고리의 다른 글
[백준] 30034 Slice String - Data Structure / Java (0) | 2023.10.08 |
---|---|
[백준] 14235 크리스마스 선물 - Data Structure / Java (0) | 2023.10.07 |
[백준] 8891 점 숫자 - Brute Force / Java (0) | 2023.10.05 |
[백준] 9291 스도쿠 채점 - Brute Force / Java (0) | 2023.10.04 |
[백준] 14584 암호 해독 - Brute Force / Java (0) | 2023.10.03 |
댓글