[비트연산] 소프티어 lv.3 CPTI [Java]
알고리즘/java 2025. 4. 7. 21:40import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] nm = br.readLine().split(" ");
int n = Integer.parseInt(nm[0]);
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
String d = br.readLine();
arr[i] = Integer.parseInt(d, 2);
}
System.out.println(checkPairs(arr));
}
public static int checkPairs(int[] binaries) {
int n = binaries.length;
int result = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
int diffCount = Integer.bitCount(bin1 ^ bin2);
if(diffCount < 3) {
result++;
}
}
}
return result;
}
}
https://softeer.ai/practice/11002
비트연산으로 풀면 쉽게 풀릴 거라고 생각했으나
bitCount 함수를 떠올리지 못해서 생각보다 애먹었던 문제
소프티어 lv.3 Hanyang Popularity Exceeding Competition (1) | 2025.04.15 |
---|---|
소프티어 lv.3 Pipelined (1) | 2025.04.13 |
[다이내믹 프로그래밍] 백준 1697번 숨바꼭질 [Java] (0) | 2025.04.09 |
[다이내믹 프로그래밍] 백준 1753번 최단경로 [Java] (0) | 2025.04.09 |
[BFS] 백준 2178번 미로 탐색 [Java] (0) | 2025.04.03 |