백준 24313번 : 알고리즘 수업 - 점근적 표기 1

2023. 10. 26. 14:48[알고리즘]/문제 풀이

 

 

 

 

 

 

 

 

풀이

 

첫번째 풀이(틀림)

- 다른 방식으로 풀어봤지만 계속 틀렸다함.

a1, a0 = map(int, input().split())
c = int(input())
n0 = int(input())

if a1*n0 + a0 <= c * n0:
	print(1)
else:
	print(0)

 

두번째 풀이(맞음)

- 찾아봤더니 a1 <= c 를 써줘야 한다고함.

- 문제에서 n0와 c는 양수이지만 a0, a1은 음수도 가능하기 때문에 만약 a1이 10일때 a0가 -100이고 n0=1이면

10 - 100이 된다. 따라서 저 조건을 넣어줘야함.

 

a1, a0 = map(int, input().split())
c = int(input())
n0 = int(input())

if (a1*n0 + a0 <= c * n0) and (a1 <= c):
	print(1)
else:
	print(0)
반응형