|
| 1 | +# 백준 16769번 \_ Mixing Milk |
| 2 | + |
| 3 | +> 시간을 줄일 수 있는 방법을 더 알아보자. |
| 4 | +
|
| 5 | +## [문제 보기](https://www.acmicpc.net/problem/16769) |
| 6 | + |
| 7 | +## 놓친 것 |
| 8 | + |
| 9 | + - 한줄로 짜면 동시에 작업이 이루어짐 |
| 10 | + - max(), min() |
| 11 | + - 함수로 따로 빼서 짜면 시간이 훨씬 많이 걸린다...(?) |
| 12 | + |
| 13 | +## 내가 짠 코드 |
| 14 | + |
| 15 | +```python |
| 16 | +def pour(next_bt, current_m, next_m): |
| 17 | + if(current_m + next_m > next_bt): |
| 18 | + current_m = current_m + next_m - next_bt |
| 19 | + next_m = next_bt |
| 20 | + return current_m, next_m |
| 21 | + else: |
| 22 | + next_m = current_m + next_m |
| 23 | + current_m = 0 |
| 24 | + return current_m, next_m |
| 25 | + |
| 26 | + |
| 27 | +bt1, m1 = map(int,input().split()) |
| 28 | +bt2, m2 = map(int,input().split()) |
| 29 | +bt3, m3 = map(int,input().split()) |
| 30 | + |
| 31 | +for i in range(33): |
| 32 | + m1, m2 = pour(bt2,m1,m2) |
| 33 | + m2, m3 = pour(bt3,m2,m3) |
| 34 | + m3, m1 = pour(bt1,m3,m1) |
| 35 | + |
| 36 | +m1, m2 = pour(bt2,m1,m2) |
| 37 | + |
| 38 | +print(m1) |
| 39 | +print(m2) |
| 40 | +print(m3) |
| 41 | +``` |
| 42 | + |
| 43 | +## 가장 적절한 코드 |
| 44 | + |
| 45 | +```python |
| 46 | +C, M = list(), list() |
| 47 | +for i in range(3): |
| 48 | + a,b = map(int, input().split()) |
| 49 | + C.append(a) |
| 50 | + M.append(b) |
| 51 | + |
| 52 | +for i in range(100): |
| 53 | + idx = i%3 |
| 54 | + nxt = (idx+1) %3 |
| 55 | + M[idx], M[nxt] = max(M[idx] -(C[nxt]-M[nxt]), 0), min(C[nxt], M[nxt]+M[idx]) |
| 56 | + |
| 57 | +for i in M: |
| 58 | + print(i) |
| 59 | +``` |
0 commit comments