본문 바로가기

binary search

알고리즘 코딩기법 - 4. 바이너리서치 안녕하세요. 오늘은 바이너리서치(Binary Search) 의 코딩법에 대해서 알아보겠습니다. 숫자맞추기 참이슬을 까고나면 병뚜껑을 꼬은 다음에 손가락으로 쳐서 끊어지면 그 전사람이 벌주를 마시는 게임이 있죠?? 그리고 나서 벌주를 마신 사람은 병뚜껑에 있는 숫자를 보고 업&다운을 해서 그 숫자를 부른 사람이 또 벌주를 마십니다. (이거 우리 학교만 하나요?) 혹시나 모르시는 분이 있을까봐 부가 설명을 드리겠습니다. 참이슬 병뚜껑에는 [1, 50] 사이의 숫자가 찍혀있습니다. 한사람씩 숫자를 부르면 정답을 아는 사람이 정답에 지금 부른 숫자보다 큰지 작은지를 알려줍니다. 그 다음 사람은 좁혀진 범위 내에서 숫자를 다시 부릅니다. 그럼 범위가 점점 좁혀지고 누군가 숫자를 맞추게 되는데 그 사람이 벌주를 마.. 더보기
Bridging signals http://acm.pku.edu.cn/JudgeOnline/problem?id=1631 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip connecting the ports of two functional blocks cross each other all over the place. At this late stage of the process, it is too expensive to redo the routing.. 더보기
TopCoder SRM 421 http://www.topcoder.com/stat?c=round_overview&er=5&rd=13512 자정에 Single Round Match 421이 있었습니다. 오늘은 250에 수치해석문제와 500에 약간 생각하기 어려운 그리디 문제가 출제되었고 그리고 1000엔 무슨 문제인지 모르겠네요^^ 항상 double형을 처리하는 문제가 나오면 그 오차때문에 틀리는 코더가 많은데 오늘도 역시 250에서 많은 사람들이 System Fail로 죽었습니다. 저는 뉴턴메소드가 오차범위내로 수렴하지 않아 TLE로 죽은듯합니다. ㅠㅠ 250 - EquilibriumPoints 질량을 가진 n개의 물질이 일직선상 고정되에 있습니다. 각각의 물질의 질량이 주어졌을 때 정확히 n-1개의 지점에서 중력장의 힘이 0이 된다.. 더보기
Subsequence http://acm.pku.edu.cn/JudgeOnline/problem?id=3061 Description A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S. Input The first line is the number of .. 더보기