[백준 1712]손익분기점 - JAVA 풀이
바로가기
문제
해석
- 고정비용 A, 가변비용 B, 판매가 C가 주어졌을 때, 손익분기점을 구하는 프로그램을 작성
풀이
가변비용 B 보다 판매가 C가 낮거나 같을 경우 이익이 나지 않는다. $(B >= C)$ 결과 -1
$x(B - C) > A$가 되면 된다. $x$의 값은 $A/(B-C) + 1$이 된다.
코드
import java.util.*;
import java.io.*;
public class Main{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int result = calc(br.readLine());
bw.write(result + "");
bw.flush();
bw.close();
}
public static int calc(String s){
StringTokenizer st = new StringTokenizer(s);
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());
int C = Integer.parseInt(st.nextToken());
if(B >= C)
return -1;
return A / (C-B) + 1;
}
}