문제 링크입니다: https://www.acmicpc.net/problem/14916
14916번: 거스름돈
첫째 줄에 거스름돈 액수 n(1 ≤ n ≤ 100,000)이 주어진다.
www.acmicpc.net
n이 최대 100,000이기 때문에 브루트포스로 접근해도 충분히 AC를 받을 수 있는 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
const int INF = 987654321; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
int result = INF; | |
for (int i = 0; i * 2 <= N; i++) | |
{ | |
if ((N - i * 2) % 5 == 0) | |
{ | |
result = min(result, (N - i * 2) / 5 + i); | |
} | |
} | |
if (result == INF) | |
{ | |
cout << -1 << "\n"; | |
} | |
else | |
{ | |
cout << result << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2530번 인공지능 시계 (0) | 2020.04.26 |
---|---|
백준 2526번 싸이클 (0) | 2020.04.26 |
백준 5568번 카드 놓기 (0) | 2020.04.21 |
백준 17609번 회문 (0) | 2020.04.20 |
백준 17088번 등차수열 변환 (0) | 2020.04.17 |