https://www.acmicpc.net/problem/1920
1920๋ฒ: ์ ์ฐพ๊ธฐ
์ฒซ์งธ ์ค์ ์์ฐ์ N(1 โค N โค 100,000)์ด ์ฃผ์ด์ง๋ค. ๋ค์ ์ค์๋ N๊ฐ์ ์ ์ A[1], A[2], โฆ, A[N]์ด ์ฃผ์ด์ง๋ค. ๋ค์ ์ค์๋ M(1 โค M โค 100,000)์ด ์ฃผ์ด์ง๋ค. ๋ค์ ์ค์๋ M๊ฐ์ ์๋ค์ด ์ฃผ์ด์ง๋๋ฐ, ์ด ์๋ค
www.acmicpc.net
๋ฐ๋ณต๋ฌธ์ผ๋ก ์ด์งํ์์ ํ์ด์ฃผ์๋ค
import sys
n = int(sys.stdin.readline().rstrip())
a = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline().rstrip())
b = list(map(int, sys.stdin.readline().split()))
a.sort()
def binary_search(start, end, target):
while start <= end:
mid = (start + end) // 2
if a[mid] == target:
return 1
elif a[mid] < target:
start = mid + 1
else:
end = mid - 1
return 0
for i in b:
print(binary_search(0, n-1, i))
'๐ค > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 1654: ๋์ ์๋ฅด๊ธฐ (Python) (0) | 2022.02.11 |
---|---|
๋ฐฑ์ค 10816: ์ซ์ ์นด๋ 2 (Python) (0) | 2022.02.10 |
๋ฐฑ์ค 1707: ์ด๋ถ๊ทธ๋ํ (Python) (0) | 2022.02.03 |
๋ฐฑ์ค 7564: ๋์ดํธ์ ์ด๋ (Python) (0) | 2022.02.03 |
๋ฐฑ์ค 2606: ๋ฒฝ ๋ถ์๊ณ ์ด๋ํ๊ธฐ (Python) (0) | 2022.02.03 |