Skip to content

Commit 54fadc5

Browse files
authored
[BOJ] 설탕 배달 / 실버4 / 30분(∆) -m "https://www.acmicpc.net/problem/2839"
1 parent 82879e7 commit 54fadc5

File tree

1 file changed

+57
-0
lines changed
  • learntosurf/Baekjoon/12_브루트 포스

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# 내 풀이
2+
N = int(input())
3+
4+
# 5kg 봉지의 최대 개수
5+
five = N //5
6+
7+
while five >= 0:
8+
# 남은 무게
9+
remain = N - (five * 5)
10+
11+
# 남은 무게가 3의 배수라면
12+
if remain % 3 == 0:
13+
# 3kg 봉지의 최대 개수
14+
three = remain // 3
15+
print(five + three) # 총 봉지 수 출력
16+
break
17+
five -= 1 # 5kg 봉지의 개수를 줄여가며 확인
18+
19+
else:
20+
print(-1) # 모든 경우를 시도해도 나누어 떨어지지 않으면 -1 출력
21+
22+
# 다른 풀이 1
23+
n = int(input())
24+
25+
if n % 5 == 0:
26+
print(n // 5)
27+
else:
28+
p = 0
29+
while n > 0:
30+
n -= 3
31+
p += 1
32+
if n % 5 == 0:
33+
p += n // 5
34+
print(p)
35+
break
36+
elif n == 1 or n == 2:
37+
print(-1)
38+
break
39+
elif n == 0:
40+
print(p)
41+
break
42+
43+
# 다른 풀이 2
44+
num = int(input())
45+
count = 0
46+
47+
while num >= 0:
48+
if num % 5 == 0:
49+
count += int(num // 5)
50+
print(count)
51+
break
52+
53+
num -= 3
54+
count += 1
55+
56+
else:
57+
print(-1)

0 commit comments

Comments
 (0)