diff --git "a/9-kyo-hwang/Greedy/\353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.cpp" "b/9-kyo-hwang/Greedy/\353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.cpp" new file mode 100644 index 0000000..623518f --- /dev/null +++ "b/9-kyo-hwang/Greedy/\353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.cpp" @@ -0,0 +1,38 @@ +#include +#include + +using namespace std; + +int solution(int Storey) +{ + int Answer = 0; + + while(Storey) + { + int Remainder = Storey % 10; + int Quotient = Storey / 10; + + if(Remainder < 5) // 예: 54 + { + Answer += Remainder; // 54 -> 50 + } + else if(Remainder > 5) // 예: 16 + { + ++Quotient; + Answer += 10 - Remainder; // 16 -> 20 + } + else + { + if(Quotient % 10 >= 5) // 예: 55 -> 60 / 25 -> 20 + { + ++Quotient; + } + + Answer += Remainder; + } + + Storey = Quotient; + } + + return Answer; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index c576a7c..0e822d3 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -58,4 +58,5 @@ | 55차시 | 2024.7.09 | Simulation | [17144 미세먼지 안녕!](https://www.acmicpc.net/problem/16934) | [#202](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/202) | | 56차시 | 2024.7.12 | Tree | [15681 트리와 쿼리](https://www.acmicpc.net/problem/15681) | [#204](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/204) | | 57차시 | 2024.7.15 | Dynamic Programming | [17070 파이프 옮기기 1](https://www.acmicpc.net/problem/17070) | [#206](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/206) | -| 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | \ No newline at end of file +| 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | +| 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | \ No newline at end of file