day8 백준 1712번 : 손익분기점 [Java]

문제출처

https://www.acmicpc.net/problem/1712

 

1712번: 손익분기점

월드전자는 노트북을 제조하고 판매하는 회사이다. 노트북 판매 대수에 상관없이 매년 임대료, 재산세, 보험료, 급여 등 A만원의 고정 비용이 들며, 한 대의 노트북을 생산하는 데에는 재료비와

www.acmicpc.net

import java.util.Scanner;
public class day008_Q1712 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int notebook = 1;
		int total = a + b;
		int income = c;
		
		while(total >= income) {
			notebook++;
			income = c * notebook;
			total = a + b * notebook;
		}
		
		System.out.println(notebook);
		sc.close();
	}

}

 

이 코드는 채점을 돌려보지는 않았지만 틀렸을것이다.

 

첫번째는

일단 문제 조건에서 손익분기점이 존재하지 않으면 -1을 출력하라고 했는데

손익분기점이 존재하지 않는 경우가 뭔지 감이 안 잡혔다.

 

1.아무리 판매해도 총생산비용을 따라잡을 수 없는경우

2.총생산비용이 없는경우(?)

 

이렇게 두가지가 떠올랐는데 2는 아예 문제의 의미가 없어져서 일단제끼고

1부터 조건문을 추가했다.

 

두번째는

분명 while문에서 시간초과가 뜰거 같았다. 

 

(c - b) * point > a가 될때 point를 구해야한다.

import java.util.Scanner;
public class day008_Q1712 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int point;
		long total = a + b;
		int income = c;
		
		if(b >= c) {
			point = -1;
		}
		else {
			point = a / (c - b) + 1;
		}
		
		System.out.println(point);
		sc.close();
	}

}
myoskin