구현, 수학

[백준] 1712. 손익분기점 풀이

hch06 2025. 2. 2. 18:34

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

 

A=고정비용
B=가변비용
C=판매가격

즉 노트북 한대 판매당 이익은 C-B이므로
이 이익으로 고정비용 A를 넘기려면(=손익분기점을 넘기려면)
{A / (C-B)}+1 만큼 판매해야 한다.

 


C

더보기
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(c - b <= 0){
        printf("-1");
        return 0;
    }
    
    int result = (a / (c - b)) + 1;
    printf("%d", result);
}

Python

더보기
a, b, c = map(int, input().split())
result = -1 if(c - b <= 0) else (a / (c - b)) + 1
print(int(result))

Java

더보기
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
      Scanner s = new Scanner(System.in);
      int a = s.nextInt(), b = s.nextInt(), c = s.nextInt();
      if(b >= c) System.out.print(-1);
      else{
          int res = (a/(c-b)) + 1;
          System.out.print(b>=c ? -1 : res);
      }
    }
}

JavaScript

더보기
ip = require('fs').readFileSync(0).toString()
var [a, b, c] = ip.split(' ').map(Number)
let res = Math.floor(a/(c-b)) + 1
console.log(b>=c ? -1 : res)