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 | 29 |
30 |
Tags
- 그리디
- 백준
- dict
- 가상메모리 관리
- 스택
- 수학
- 파이썬
- 다이나믹 프로그래밍
- 운영체제
- python
- 재귀
- 프로그래머스
- 구현
- DP
- 힙
- level0
- N과M
- level3
- MYSQL
- level1
- 코딩테스트
- BOJ
- BFS
- programmers
- 가상메모리
- 다익스트라
- dfs
- 브루트포스
- level2
- 딕셔너리
Archives
- Today
- Total
동캄의 코딩도장
백준 1449 [수리공 항승] 파이썬 본문
https://www.acmicpc.net/problem/1449
1449번: 수리공 항승
첫째 줄에 물이 새는 곳의 개수 N과 테이프의 길이 L이 주어진다. 둘째 줄에는 물이 새는 곳의 위치가 주어진다. N과 L은 1,000보다 작거나 같은 자연수이고, 물이 새는 곳의 위치는 1,000보다 작거나
www.acmicpc.net
#백준 1449
N,L=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
s=[]
for i in range(len(lst)-1):
s.append(lst[i+1]-lst[i])
ans=0
d=0
i=0
while i<(N-1):
if d+s[i]>(L-1):
ans+=1
i+=1
d=0
else:
d+=s[i]
i+=1
print(ans+1)
#백준 1449 다른 풀이
n, l = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
start = s[0]
end = s[0] + l
cnt = 1
for i in range(n):
if start <= s[i] < end:
continue
else:
start = s[i]
end = s[i] + l
cnt += 1
print(cnt)
'코테 > BOJ' 카테고리의 다른 글
백준 2012 [등수 매기기] 파이썬 (0) | 2022.09.03 |
---|---|
백준 11501 [주식]파이썬 (2) | 2022.09.03 |
백준 16162 [가희와 3단 고음] 파이썬 (0) | 2022.09.03 |
백준 20300 [서강근육맨] 파이썬 (0) | 2022.09.03 |
백준 6593 [상범 빌딩] 파이썬 (0) | 2022.09.03 |