Skip to content

Commit 054ed50

Browse files
committed
[ADD] BOJ 4796 캠핑
- 그리디 알고리즘
1 parent a65f56a commit 054ed50

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

acmicpc.net/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@
706706
| 27 | [방탈출](https://www.acmicpc.net/problem/15729) | [cpp](source/15729.cpp) | 28 | [세탁소 사장 동혁](https://www.acmicpc.net/problem/2720) | [cpp](source/2720.cpp) |
707707
| 29 | [욱제는 도박쟁이야!!](https://www.acmicpc.net/problem/14655) | [cpp](source/14655.cpp) | 30 | [Project Teams](https://www.acmicpc.net/problem/20044) | [cpp](source/20044.cpp) |
708708
| 31 | [수강변경](https://www.acmicpc.net/problem/23305) | [cpp](source/23305.cpp) | 32 | [온라인 판매](https://www.acmicpc.net/problem/1246) | [cpp](source/1246.cpp) |
709+
| 33 | [캠핑](https://www.acmicpc.net/problem/4796) | [cpp](source/4796.cpp) | | | |
709710

710711
</details>
711712

acmicpc.net/source/4796.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 4796. 캠핑
2+
// 2022.03.12
3+
// 그리디 알고리즘
4+
#include<iostream>
5+
6+
using namespace std;
7+
8+
int main()
9+
{
10+
int l, p, v;
11+
int cnt = 0;
12+
while (1)
13+
{
14+
cnt++;
15+
cin >> l >> p >> v;
16+
if (l == 0 and p == 0 and v == 0)
17+
{
18+
break;
19+
}
20+
21+
int ans = 0;
22+
ans += (v / p) * l;
23+
24+
// 잔여로 쉴수 있을때는 무조건 최대로 쉰다.
25+
ans += v % p > l ? l : v % p;
26+
cout << "Case " << cnt << ": " << ans << endl;
27+
}
28+
return 0;
29+
}

0 commit comments

Comments
 (0)