[백준/파이썬] 11606번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 11606번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
There is a classic riddle where you are given two eggs and a k-floor building and you want to know the highest floor from which you can drop the egg and not have it break.
It turns out that you have stumbled upon some logs detailing someone trying this experiment! The logs contain a series of floor numbers as well as the results of dropping the egg on those floors. …
입력 요약
The first line of input contains two space-separated integers n and k (1 ≤ n ≤ 100, 3 ≤ k ≤ 100), the number of egg drops and the number of floors of the building, respectively. …
출력 요약
Print, on a single line, two integers separated by a single space. The first integer should be the number of the lowest floor from which you can drop the egg and it could break and still be consistent with the results. …
코드
n,k=map(int,input().split())
m,M=k,1
l=[list(input().split())for _ in range(n)]
for i in l:
a,b=int(i[0]),i[1]
if b=='SAFE':M=max(M,a)
elif b=='BROKEN':m=min(m,a)
print(M+1,m-1)
설명
핵심은 구현 관점에서 There is a classic riddle where you are given two eggs and a k-floor building and you want to know the highest floor from which you can drop the egg a …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기