알고리즘/백준 알고리즘

[백준] 1712 - 손익분기점

TIM_0529 2022. 12. 30. 06:08
반응형
#include <iostream>
#include <vector>
using namespace std;


int main()
{
	int permentCost;
	int costPerWork;
	int priceOfLap;
	cin >> permentCost >> costPerWork >> priceOfLap;
	
	if (costPerWork > priceOfLap || costPerWork == priceOfLap)
		cout << -1;
	else {
		cout << permentCost / (priceOfLap - costPerWork) + 1;
	}
    return 0;
}

예제에서 공식을 찾아서 간단하게 풀어봤습니다.

 

C++을 사용했고 메모리는 2020KB 사용했습니다.

 

다른 사람의 코드도 확인해 보겠습니다.

#include<stdio.h>
int main(){
	int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    printf("%d",C<=B?-1:A/(C-B)+1);
}

C스타일로 작성하셨고 삼항문을 사용해서 한 줄로 간단하게 정리해서 푸셨습니다.

메모리는 1112KB 사용하셨습니다.

반응형

'알고리즘 > 백준 알고리즘' 카테고리의 다른 글

[백준] 1193 - 분수찾기  (0) 2022.12.31
[백준] 2292 - 벌집  (2) 2022.12.30
[백준] 1316-그룹단어 체커  (2) 2022.12.29
[백준] 2941 - 크로아티아 알파벳  (2) 2022.12.29
[백준] 5622 - 다이얼  (0) 2022.12.29