ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [1일 1백준 : 1712번] 손익분기점
    Programming/백준 2021. 1. 28. 01:57
    1 2 3 4 5 6 7 8 9 10 11 (손익분기점)
    1070 1140 1210 1280 1350 1420 1490 1560 1630 1700 1770
    170 340 510 680 850 1020 1190 1360 1530 1700 1870

    손익분기점이 존재하지 않는 경우는 가변비용(B)이 대당 가격(C)보다 높거나 같을때이다. (B >= C)

     

    처음에는 정석대로 아래와 같이 직접 더해가면서 손익분기점을 찾아냈지만 시간초과가 떳다.

    그래서 두번째 방식으로 해결 할 수 있었다.

    두번째 방식은 인건비 포함 한 가변비용과 컴퓨터 한 대당 가격을 뺌으로써 순이익을 계산하고,

    그 순이익이 앞으로 몇번 더 걸치게 되면 이윤이 발생하는지만 계산하면 되는데 기존에 1000만원이 고정 지출이기 때문에 고정 지출금(A) - 순이익 + 1을 통해서 결과를 도출해낼 수 있었다.

    여기서 +1을 해준이유는 이익이 발생했을 때의 분기점이기 때문에 해줬다.

     

    정석대로 (시간초과)

    int main(void)
    {
    	std::cin.tie(NULL);
    	std::cout.tie(NULL);
    	std::ios::sync_with_stdio(false);
    
    	unsigned long A, B, C;
    
    	std::cin >> A >> B >> C;
    
    	if (B >= C) {
    		std::cout << "-1" << "\n";
    		return 0;
    	}
    
    	unsigned long totalCost = 0, totalProfit = 0;
    
    	totalCost = A;
    	unsigned long i = 0;
    	for (i = 0; totalCost + B > totalProfit; i++)
    	{
    		totalCost += B;
    		totalProfit += C;
    	}
    	std::cout << i << "\n";
    	return 0;
    }

     

    두번째 방식

    int main(void)
    {
    	std::cin.tie(NULL);
    	std::cout.tie(NULL);
    	std::ios::sync_with_stdio(false);
    
    	unsigned long A, B, C;
    
    	std::cin >> A >> B >> C;
    
    	if (B >= C) {
    		std::cout << "-1" << "\n";
    		return 0;
    	}
    
    	unsigned long diff =  C - B;
    	unsigned long result = (int)(A / diff) + 1;
    
    	std::cout << result << "\n";
    	return 0;
    }

     

Designed by Tistory.