From 90417cebe52941f0bc7282ddc3f631b267a6529d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A7=84?= Date: Tue, 26 Aug 2025 16:40:55 +0900 Subject: [PATCH] =?UTF-8?q?[20250826]=20BOJ=20/=20G1=20/=20=EB=8F=99?= =?UTF-8?q?=EC=A0=84=20=EB=92=A4=EC=A7=91=EA=B8=B0=20/=20=EA=B9=80?= =?UTF-8?q?=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\222\244\354\247\221\352\270\260.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "zinnnn37/202508/26 BOJ G1 \353\217\231\354\240\204 \353\222\244\354\247\221\352\270\260.md" diff --git "a/zinnnn37/202508/26 BOJ G1 \353\217\231\354\240\204 \353\222\244\354\247\221\352\270\260.md" "b/zinnnn37/202508/26 BOJ G1 \353\217\231\354\240\204 \353\222\244\354\247\221\352\270\260.md" new file mode 100644 index 00000000..99b14e44 --- /dev/null +++ "b/zinnnn37/202508/26 BOJ G1 \353\217\231\354\240\204 \353\222\244\354\247\221\352\270\260.md" @@ -0,0 +1,69 @@ +```java +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +public class BJ_1285_동전_뒤집기 { + + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + private static int N; + private static int ans; + private static int[] coins; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + ans = Integer.MAX_VALUE; + + coins = new int[N]; + for (int i = 0; i < N; i++) { + String s = br.readLine(); + for (int j = 0; j < N; j++) { + if (s.charAt(j) == 'T') { + coins[i] += (1 << j); + } + } + } + } + + private static void sol() throws IOException { + // 행 뒤집기 + for (int rowFillped = 0; rowFillped < (1 << N); rowFillped++) { + // 뒷면 + int totalTails = 0; + + for (int row = 0; row < N; row++) { + // 0일 때 뒤집지 않고(0), 1일 때 뒤집을 때(1) 0이 되어야 해서 XOR 연산 + int tailsInCol = Integer.bitCount(coins[row] ^ rowFillped); + totalTails += Math.min(tailsInCol, N - tailsInCol); + } + ans = Math.min(ans, totalTails); + } + + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + + private static int countTails(boolean[][] arr) { + int cnt = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (arr[i][j]) { + cnt++; + } + } + } + return cnt; + } +} +``` \ No newline at end of file