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
1. ์ฝ๊ฒ ๊ฐ๋ ค๊ณ ํ์ง๋ง...ํธ๋ฝํธ๋ฝํ์ง ์์ ๋ฐฑ์ค...
์๊ฐ์ด๊ณผ๋ฅผ ๋นํ๋ค.
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))
for i in range(m):
if B[i] in A:
print(1)
else:
print(0)
2. ๊ฒฐ๊ตญ ์ด์งํ์์ ์ด์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ๋ค์ ํ์๋ค!
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
A.sort() #์ด์งํ์์ ์ํsort
m = int(input())
B = list(map(int,input().split()))
for i in range(m):
target = B[i]
flag = 0
left = 0
right = n-1
while left<=right:
mid = (left+right)//2
if A[mid] == target:
flag=1 # A์์ target์ด ์์ผ๋ฉด 1
break
elif A[mid]> target:
right = mid-1
else:
left = mid+1
print(flag)
'Problem Solving > BAEKJOON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [baekjoon]python #10773 ์ ๋ก (0) | 2022.06.23 |
|---|---|
| [baekjoon]python #10816 ์ซ์ ์นด๋ 2 (0) | 2022.06.03 |
| [baekjoon]python #1018 ์ฒด์คํ ๋ค์ ์น ํ๊ธฐ (0) | 2022.06.03 |
| [baekjoon]python #2231 ๋ถํดํฉ (0) | 2022.06.03 |
| [baekjoon]python #1929 ์์ ๊ตฌํ๊ธฐ (0) | 2022.06.03 |
๋๊ธ