[BOJ] 1193: λΆ„μˆ˜μ°ΎκΈ°

ohhj1999Β·2021λ…„ 7μ›” 30일
0

[BOJ] Algorithm Solving

λͺ©λ‘ 보기
18/62
post-thumbnail

πŸ”’ 예제

>> 14

2/4

πŸ”§ 풀이

1. x = int(sys.stdin.readline().rstrip())
2. κ·œμΉ™ μ°ΎκΈ° : (1/1) - (1/2 - 2/1) - (3/1 - 2/2 - 1/3) 
    		- (1/4 - 2/3 - 3/2 - 4/1) - ...
    2.1 (1) - (2) - (3) - (4) - ... 둜 개수 증가
    2.2 n: λͺ‡ 번째 ()인지 νŒŒμ•…    
   
3. μΌ€μ΄μŠ€ λ‚˜λˆ„κΈ°
    3.1 λΆ„λͺ¨κ°€ ν™€μˆ˜λ‘œ μ‹œμž‘ν•˜λŠ” 경우: n/1 -> n-i/1+i -> 1/n 
    3.2 λΆ„λͺ¨κ°€ 짝수둜 μ‹œμž‘ν•˜λŠ” 경우: 1/n -> 1+i/n-i -> n/1
    3.3 i == tmp % n

πŸ”‘ λ‹΅μ•ˆ

import sys

x = int(sys.stdin.readline().rstrip())

tmp = x
for n in range(1, x+1):
    tmp -= n
    # <= 주의 !!!
    if tmp <= 0:
        if n % 2 == 0:
            c = n - abs(tmp)
            p = 1 + abs(tmp)
        else:
            c = 1 + abs(tmp)
            p = n - abs(tmp)
        break

print(str(c)+'/'+str(p))

πŸ’‘ κ°œλ…

0개의 λŒ“κΈ€