본문 바로가기

코딩

[Python] 백준 #24313. 알고리즘 수업 - 점근적 표기 1

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

 

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

f(n) = 7n + 7, g(n) = n, c = 8, n0 = 1이다. f(1) = 14, c × g(1) = 8이므로 O(n) 정의를 만족하지 못한다.

www.acmicpc.net

 

# 24313 - Python 3

import sys

input = sys.stdin.readline

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

if a1 * n0 + a0 <= c * n0 and a1 <= c: # 값 비교 + 기울기 비교(n>=n0인 모든 n에서 성립하기 위하여)
    print(1)
else:
    print(0)

< line 9 >

- a1 * n0 <= c * n0

: f(n) <= c * g(n)의 조건

 

- a1 <= c

: n >= n0인 모든 n에서 위 식이 성립할 조건 (기울기의 비교)