[๋ฐฑ์ค-2776] ์๊ธฐ์ / Python
๐ Problem Solving/Baekjoon
https://www.acmicpc.net/problem/2776
2776๋ฒ: ์๊ธฐ์
์ฐ์ข ์ด๋ ์์ฒญ๋ ๊ธฐ์ต๋ ฅ์ ๊ฐ์ง๊ณ ์๋ค. ๊ทธ๋์ ํ๋ฃจ ๋์ ๋ณธ ์ ์๋ค์ ๋ชจ๋ ๊ธฐ์ต ํ ์ ์๋ค. ํ์ง๋ง ์ด๋ฅผ ๋ฏฟ์ ์ ์๋ ๋๊ท๋ ๊ทธ์ ๊ธฐ์ต๋ ฅ์ ์ํํด ๋ณด๊ธฐ๋ก ํ๋ค. ๋๊ท๋ ์ฐ์ข ์ ๋ฐ๋ผ ๋ค๋๋ฉฐ,
www.acmicpc.net
import sys
def binary_search(start, end, note1, num):
while start <= end:
mid = (start+end)//2
if note1[mid] == num:
return 1
elif note1[mid] < num:
start = mid + 1
else:
end = mid - 1
return 0
for _ in range(int(sys.stdin.readline())):
n = int(sys.stdin.readline())
note1 = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
note2 = list(map(int, sys.stdin.readline().split()))
note1.sort()
for num in note2:
print(binary_search(0, n-1, note1, num))
ํด์ค
๊ฐ๋จํ ์ด๋ถํ์ ๋ฌธ์ . ๋ ธํธ1์ ์ ๋ ฌํด์ค ํ, ๋ ธํธ2์ ๋ฐ์ดํฐ๋ก ๋ ธํธ1์์ ์ด๋ถํ์์ ์งํํ๋ฉด ๋๋ค.
'๐ Problem Solving > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค-1932] ์ ์ ์ผ๊ฐํ / Python (0) | 2021.05.19 |
---|---|
[๋ฐฑ์ค-17626] Four Squares / Python (1) | 2021.05.18 |
[๋ฐฑ์ค-2343] ๊ธฐํ ๋ ์จ / Python (0) | 2021.05.18 |
[๋ฐฑ์ค-2822] ์ ์ ๊ณ์ฐ / Python (0) | 2021.05.18 |
[๋ฐฑ์ค-11728] ๋ฐฐ์ด ํฉ์น๊ธฐ / Python (0) | 2021.05.18 |