https://www.acmicpc.net/problem/10162
풀이
최소 버튼 조작으로 정해진 요리시간을 만들 수 있는지 구하는 문제입니다.
그리디 알고리즘을 사용해 문제를 해결할 수 있습니다.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// freopen("input.txt", "r", stdin);
int time;
cin >> time;
int a_bt = 300;
int b_bt = 60;
int c_bt = 10;
vector<int> v(3, 0);
v[0] = time / a_bt;
time = time % a_bt;
v[1] = time / b_bt;
time = time % b_bt;
v[2] = time / c_bt;
time = time % c_bt;
if (time == 0)
cout << v[0] << " " << v[1] << " " << v[2] << endl;
else
cout << -1 << endl;
return 0;
}
'백준' 카테고리의 다른 글
[Python] 백준 9935번 문자열 폭발 (0) | 2024.09.27 |
---|---|
[Python] 백준 대피소 (1) | 2024.09.25 |
[C++] 백준 세탁소 사장 동혁 (0) | 2024.06.20 |
[C++] 백준 고층 건물 (0) | 2024.06.18 |
[C++] 백준 투명 (0) | 2024.06.18 |