[백준/파이썬] 16648번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 16648번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Anna loves her cell phone and becomes very sad when its battery level drops to 0 percent.
In normal mode, Anna’s phone battery drains at a constant speed. When the battery level reaches 20 percent, the phone automatically switches to eco mode. In eco mode, the battery drains two times slower than in normal mode.
Alex has invited Anna for a date. Anna needs t minutes to get from her home to the meeting place. When Anna leaves home, her phone’s battery level is 100 percent. …
입력 요약
The only line of the input contains two integers t and p — time Anna needs to get from her home to the meeting place, in minutes, and the battery level of her phone at the moment of meeting, in percent (1 ≤ t ≤ 360; 1 ≤ p ≤ 99).
출력 요약
Output a single real number — time since the moment of meeting before Anna’s phone runs out of battery, in minutes.
Your answer will be considered correct if its absolute or relative error doesn’t exceed 10−4.
코드
t, p = map(int, input().split())
ec = max(0, 20-p)
tpb = t / (2*ec + min(80, 100-p))
print(min(20,p)*tpb*2 + max(0, p-min(20,p))*tpb)
설명
핵심은 구현 관점에서 Anna loves her cell phone and becomes very sad when its battery level drops to 0 percent. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기