백준알고리즘
백준 1712 C++
컨트롤디
2021. 7. 2. 18:51
#include <iostream>
using namespace std;
int main(){
int x;
int fix_cost; // 고정비용
int cha_cost; // 가변비용
int total_cost; // 총 비용
cin >> fix_cost >> cha_cost >> total_cost;
if((total_cost-cha_cost) == 0){
cout << -1;
return 0;
}
x = fix_cost / (total_cost-cha_cost) + 1;
if(x < 0) cout << -1;
else cout << x;
return 0;
}
수식 : A + Bx < Cx
이를 x에 대해 정리하면,
A / (C-B) < x 이므로,
x 는 A/(C-B) + 1 이면된다
그리고 C-B 가 0일때는 -1를 출력하도록 하지않으면 런타임에러가 발생한다