[Java | 백준 1712] 손익분기점
· 테크· Java
Java
백준 1712 www.acmicpc.net/problem/1712
풀이
손익분기점은 수익이 비용을 넘어서는 그 지점을 알아내는 문제이다.
이 문제의 주의점은
1. 시간초과이다. 0.35초로 시간이 한정되어 있기 때문에 반복된 for 문을 이용한 풀이는 시간을 벗어난다.
2. 손익분기점이 존재하지 않으면 -1 을 출력한다는 점이다.
입력 순서대로 a 는 고정비용, b 는 가변비용, c 는 수익이다.
수익이 비용을 넘어설 수 없는 즉, 손익분기점이 존재하지 않게 되는 경우는 수익이 증가하는 가변비용을 넘어설 수 없을 때이다.
그 외의 손익분기점이 존재하는 경우는 a+b*n < c*n 의 n 값인데, 정리하면
a+(b-c)*n < 0
n < -a/(b-c)
즉, 실제 손익분기점 n의 값은 -a/(b-c)+1 이 되어야 한다. → answer = a/(c-b)+1;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import java.util.Scanner;
public class math_1712 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
long b = sc.nextLong();
long c = sc.nextLong();
sc.nextLine();
long answer;
if(c<=b) System.out.println(-1);
else {
answer = a/(c-b)+1;
System.out.println(answer);
}
sc.close();
}
}
|
cs |
Comments
No comments yet. Be the first!
319 posts in 테크
- 368Supabase 프로젝트 복사하기 (Restore to a New Project)NEW
- 341Migrating from Permanent Access Tokens to Token Exchange — Why Order Matters
- 326Startup & Product Glossary: Terms Every Solo Founder Should Know
- 325Context Management — How I Do It Now
- 324Claude Code Routines vs Cowork Schedule — What's the Difference?
1–5 / 319