https://www.acmicpc.net/problem/2839
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include<iostream> using namespace std; int main() { int input; int a = 0 , b = 0; cin >> input; if (input == 4 || input == 7) { cout << -1; return 0; } while (input > 0) { if (input % 5 == 0) { a = input / 5; break; } else { input = input - 3; b++; } } cout << a + b << endl; } | cs |
Mirko works in a sugar factory as a delivery boy. He has just received an order: he has to deliver exactly N kilograms of sugar
to a candy store on the Adriatic coast. Mirko can use two types of packages, the ones that contain 3 kilograms, and the ones
with 5 kilograms of sugar.
Mirko would like to take as few packages as possible. For example, if he has to deliver 18 kilograms of sugar,
he could use six 3-kilogram packages. But, it would be better to use three 5-kilogram packages, and one 3-kilogram package,
resulting in the total of four packages.
Help Mirko by finding the minimum number of packages required to transport exactly N kilograms of sugar.
The first and only line of input contains one integer N (3 ≤ N ≤ 5000).
The first and only line of output should contain the minimum number of packages Mirko has to use. If it is impossible
to deliver exactly N kilograms, output -1.
'Algorithm Problems > BOJ' 카테고리의 다른 글
[2439번] Star Shooting 2 별찍기2 - For loop [C++] (0) | 2016.12.28 |
---|---|
[10845번] QUEUE 큐 - Queue [C++] (0) | 2016.12.27 |
[11718번] Output as is 그대로 출력하기 - In/Output[C++] (0) | 2016.12.27 |
[4673번] Self Number 셀프 넘버 - Method[Java] (0) | 2016.12.22 |
[11718번] Output as is 그대로 출력하기 - In/Output[Java] (0) | 2016.12.22 |