※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 24805번 문제인 Climbing Worm이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/24805
24805번: Climbing Worm
The input consists of a single line that contains three integers $a, b$ ($0 \leq b < a \leq 100$), and $h$, ($0 < h \leq 100\,000$) indicating the amount $a$ of inches the worm can climb at a time, the amount $b$ of inches the worm falls during its resting
www.acmicpc.net
모든 입력은 음이 아닌 정수로 주어지고 높이는 10만 이하이므로, 벌레는 많아봐야 10만번 이하 횟수로 기어오르는 시도를 하게 될 것이다.
이는 벌레가 기어오르는 행동 전체를 직접 시뮬레이션하는 것으로 문제를 해결할 수 있는 크기의 입력이다.
벌레의 움직임을 시뮬레이션하는 코드를 작성해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int cnt = 0;
int cur = 0;
int sU, sD, H; cin >> sU >> sD >> H;
while (1) {
cur += sU, cnt++;
if (cur >= H) break;
cur -= sD;
}
cout << cnt;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 24807 // C++] Math Homework (0) | 2022.05.08 |
---|---|
[BOJ 6032 // C++] Toy Shopping (0) | 2022.05.08 |
[BOJ 6504 // C++] 킬로미터를 마일로 (0) | 2022.05.08 |
[BOJ 5972 // C++] 택배 배송 (0) | 2022.05.08 |
[BOJ 6031 // C++] Feeding Time (0) | 2022.05.08 |