728x90
6794번: What is n, Daddy?
Natalie is learning to count on her fingers. When her Daddy tells her a number n (1 ≤ n ≤ 10), she asks “What is n, Daddy?”, by which she means “How many fingers should I hold up on each hand so that the total is n?” To make matters simple, her
www.acmicpc.net
문제 풀이
1 부터 10까지의 수를 두 손으로 표현할 수 있는 방법의 수를 출력해주는 문제이다.
본인은 왼손이 항상 더 큰 수를 가지는 것으로 풀었다.
반복 규칙 (n 일 경우)
- 왼손이 항상 오른손보다 크거나 같아야한다.
- 왼손과 오른손의 손가락 수가 n보다 작을 경우, 왼손 손가락 하나 증가
- 왼손과 오른손의 손가락 수가 n과 같을 경우, 정답 1 증가, 오른손 1 증가, 왼손 0으로 초기화
- 반복할 때마다 왼손 1 증가, 왼손이 5일 경우, 오른손 1 증가
정답 코드
n = int(input())
l, r, ans= 0, 0, 0
while l <= 5 and r <= 5 :
if l + r == n and l >= r :
ans += 1
r += 1
l = 0
if l == 5 : r += 1
else : l += 1
print(ans)
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 6830 - It’s Cold Here! [python] (0) | 2023.03.19 |
---|---|
[BOJ/백준] 6812 - Good times [python] (0) | 2023.03.19 |
[BOJ/백준] 6784 - Multiple Choice [python] (0) | 2023.03.19 |
[BOJ/백준] 6780 - Sumac Sequences [python] (0) | 2023.03.19 |
[BOJ/백준] 6779 - Who Has Seen The Wind [python] (0) | 2023.03.19 |