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 | 31 |
Tags
- level2
- 재귀
- 백준
- 수학
- BFS
- level0
- level3
- level1
- 가상메모리 관리
- BOJ
- MYSQL
- python
- 프로그래머스
- DP
- 브루트포스
- 딕셔너리
- 가상메모리
- programmers
- dict
- 스택
- 코딩테스트
- 운영체제
- 구현
- 힙
- N과M
- 그리디
- 파이썬
- 다이나믹 프로그래밍
- 다익스트라
- dfs
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 |