Algorithm
[BOJ] 4796번 : 캠핑
rudgh99_algo
2024. 9. 26. 22:13
1. problem :
https://www.acmicpc.net/problem/4796
2. solution 1 :
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int i = 0;
while (true) {
i++;
long long l, p, v;
cin >> l >> p >> v;
if (l == 0 && p == 0 && v == 0) return 0;
long long ans = 0;
long long div = v / p;
ans += div * l;
if (v - div * p > l) ans += l;
else ans += v - div * p;
cout << "Case " << i << ": " << ans << '\n';
}
}
p를 이용해 몫을 구한 다음, ans에 더해주고, 나머지값이 l보다 큰지 작은지에 따라 처리를 해주었다.
3. solution 2 :
// Authored by : heheHwang
// Co-authored by : BaaaaaaaaaaarkingDog
// http://boj.kr/d52d24386b4f4b1a9b3afe25dfc3eea2
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int i = 1;
while (1) {
int L, P, V;
cin >> L >> P >> V;
if (V == 0) break;
cout << "Case " << i++ << ": " << V / P * L + min(V % P, L) << '\n';
}
}
source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x12/solutions/4796.cpp
basic-algo-lecture/0x12/solutions/4796.cpp at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
다음번에는 이렇게 풀어봐야겠다. min을 이용해서