알고리즘 문제/BOJ
2869번 달팽이는 올라가고 싶다
parkit
2018. 10. 21. 01:46
728x90
반응형
https://www.acmicpc.net/problem/2869
예제 및 다른 테스트 케이스들을 활용하여
내가 생각한 과정을 적으면서 코드를 작성하였다.
아래는 내가 생각한 과정 케이스들이다.
3 1 6
답 3
6 - 3 = 3
3 - 1 = 2
3 / 2 = 1
1*(3 - 1) + 3 >= 6 ? No
2 1 5
답 4
5 - 2 = 3
2 - 1 = 1
3 / 1 = 3
3 * (2 - 1) + 2 >= 5 ? Yes 그렇다면 3 + 1
5 2 100
답 33
100 - 5 = 95
5 - 2 = 3
95 / 3 = 31
31 * (5 - 2) + 5 >= 98? No
4 2 100
답 49
100 - 4 = 96
4 - 2 = 2
96 / 2 = 48
48 * (4 - 2) + 4 >= 100? Yes 그렇다면 48 + 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; int A = 0, B = 0, V = 0; int main(void) { scanf("%d %d %d", &A, &B, &V); if (A >= V) printf("1\n"); else { int VA = V - A, AB = A - B; if ((VA / AB) * AB + A >= V) printf("%d\n", VA / AB + 1); else printf("%d\n", VA / AB + 2); } return 0; } | cs |
728x90
반응형