Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 2839번 - 설탕 배달 본문
greedy하게 풀었다
이게 greedy하게 푸는 방법이라 내가 쓴 코드가 정답이 아닐 수도 있다
다른 블로그들 참고하니까 dq로 푸는 방법도 있는 것 같은데
아직은 dq를 모르므로 pass
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
int bags = 0;
while (n >= 0) {
if (n % 5 == 0) {
bags += (n / 5);
cout << bags << endl;
return 0;
}
n -= 3;
bags++;
}
cout << -1 << endl;
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 15596번 정수 N개의 합 (0) | 2021.08.07 |
|---|---|
| [C++] 백준 11051번 이항 계수 2 (0) | 2021.08.05 |
| [C++] 백준 12605번 단어순서 뒤집기 (0) | 2021.08.04 |
| [C++] 백준 2805번 나무 자르기 (0) | 2021.08.04 |
| [C++] 백준 1021번 회전하는 큐 (0) | 2021.08.04 |
Comments