RUBY

[백준] 수 찾기 본문

PS/BOJ

[백준] 수 찾기

RUBY_루비 2020. 9. 15. 23:59

출처::  www.acmicpc.net/problem/1920

분류:: 이진탐색 

 

1. 문제 이해 및 해결과정

 

2. 풀이방법

 1. python

#수 찾기
#https://www.acmicpc.net/problem/1920
import sys
sys.stdin = open("input.txt","r")
n=int(input())
a=list(map(int,input().split()))
m=int(input())
find=list(map(int,input().split()))
a.sort()
def binary_search(x):
    left=0
    right=n-1
    while left<=right:
        mid=(left+right)//2
        if a[mid]==x:
            return 1
        elif a[mid]>x:
            right=mid-1
        else:
            left=mid+1
    return 0

for x in find:
    sol=binary_search(x)
    print(sol)

 

3. 오답원인

 

4. 알게된 점

 

'PS > BOJ' 카테고리의 다른 글

[백준] 집합의 표현  (0) 2020.09.16
[백준] 예산  (0) 2020.09.15
[백준] 게임개발  (0) 2020.09.15
[백준] 줄세우기  (0) 2020.09.15
[백준] 드래곤 커브 | 삼성  (0) 2020.09.14
Comments