Skip to content

Commit 25c8b62

Browse files
committed
비트 우정지수 풀이
1 parent e437a6b commit 25c8b62

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 그리디 알고리즘
2+
# https://www.acmicpc.net/problem/12782
3+
4+
import sys
5+
6+
input = sys.stdin.readline
7+
T = int(input())
8+
Q = []
9+
10+
for _ in range(T):
11+
A,B = input().split()
12+
Q_ = 0
13+
A_ = {"0":0, "1":0}
14+
B_ = {"0":0, "1":0}
15+
for i in range(len(A)):
16+
if A[i] != B[i]:
17+
Q_ += 1
18+
A_[A[i]] += 1
19+
B_[B[i]] += 1
20+
21+
if A_["0"] and B_["0"]:
22+
# 비트의 숫자를 바꿔서 해결하려면 2번이 필요하고, 교환은 1번이면 되므로
23+
# swap 횟수만큼 답에서 빼주면 된다.
24+
swap = min(A_["0"], B_["0"])
25+
Q_ -= swap
26+
27+
Q.append(str(Q_))
28+
29+
print("\n".join(Q))

BAEKJOON/3Gold/대표 선수.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#
1+
# 자료 구조, 정렬, 우선순위 큐, 투 포인터
22
# https://www.acmicpc.net/problem/2461
33

44
import sys

0 commit comments

Comments
 (0)