Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 완전탐색
- NaverAItech
- leetcode
- github
- pytorch
- 프로그래머스
- 네이버AItech
- NLP
- vscode
- FDS
- python
- 코딩테스트
- DeepLearning
- rnn
- torchserve
- GIT
- autoencoder
- GCP
- PytorchLightning
- Kaggle
- datascience
- 백준
- FastAPI
- 알고리즘
- docker
- Matplotlib
- wandb
- GitHub Action
- pep8
- Kubernetes
Archives
- Today
- Total
Sangmun
백준 17976번 Thread knots 본문
17976번: Thread Knots (acmicpc.net)
* 이분 탐색으로 풀이하는 문제
import sys
input = sys.stdin.readline
n = int(input())
lines = []
for _ in range(n):
a,b = map(int,input().split())
lines.append((a,b))
lines.sort()
def search(x):
before = lines[0][0]
for each in lines[1:]:
now = each[0]
if now - before < x:
tmp = before + x
if each[0] <= tmp <= each[0] + each[1]:
before = tmp
else:
return False
else:
before = now
return True
start = 0
end = 2000000000
while start <= end:
mid = (start + end) // 2
result = search(mid)
# 이분탐색으로 문제 풀이
if result:
start = mid + 1
else:
end = mid - 1
if result: print(mid)
else: print(mid-1)
'알고리즘 > 백준' 카테고리의 다른 글
백준 1495번 기타리스트 (0) | 2023.02.06 |
---|---|
백준 7490번 0 만들기 (0) | 2023.02.04 |
백준 1449번 수리공 (0) | 2023.02.03 |
백준 1049번 기타줄 (0) | 2023.02.03 |
백준 11057 오르막 수 (0) | 2022.12.22 |
Comments