10815번: 숫자 카드
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
✓ 난이도 : 실버 5
✓ 문제 풀이 : 이분탐색
백준 1920. 수찾기와 유사한 문제
<이분탐색 사용>
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
m = int(input())
chk = list(map(int, input().split()))
num.sort()
for c in chk:
s, e = 0, n-1
ans = 0
while s <= e:
mid = (s+e)//2
if num[mid] == c:
ans = 1
break
elif num[mid] < c:
s = mid+1
else:
e = mid -1
print(ans, end=' ')
<set 사용>
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
m = int(input())
chk = list(map(int, input().split()))
num = set(num)
for c in chk:
if c in num:
print(1, end=' ')
else:
print(0, end=' ')
'Python > 코딩테스트' 카테고리의 다른 글
| [백준] 1822. 차집합 (0) | 2023.10.12 |
|---|---|
| [백준] 10816. 숫자 카드 2 (0) | 2023.10.09 |
| [백준] 1920. 수찾기 (0) | 2023.10.09 |
| [백준] 2330번 : 수 고르기 (1) | 2023.09.23 |
| [백준] 구현 기초 - 별 찍기 1~7 (0) | 2023.09.21 |