Posts
All the articles I've posted.
BOJ1011GOLD 5
import sys, math
i = int(sys.stdin.readline())
for _ in range(i):
n, m = map(int, sys.stdin.readline().split())
N = m - n
r_N = math.sqrt(N)
N_int = math.trunc(r_N)
if r_N == N_int: print(N_int * 2 - 1)
else:
if N > N_int * (N_int + 1):
print(N_int * 2 + 1)
else:
print(N_int * 2)Fly me to the Alpha Centauri
백준 1011번 'Fly me to the Alpha Centauri' (골드 5) 문제 풀이. math 로 접근했다.
BOJ1074SILVER 1
...
num = 2 ** (N - 1)
# 좌상단
if x <= num and y <= num:
position(N-1, x, y, base)
# 우상단
elif x > num and y <= num:
position(N-1, x - num, y, 4 ** (N - 1) + base)
# 좌하단
elif x <= num and y > num:
position(N-1, x, y - num, 2 * 4 ** (N - 1) + base)
# 우하단
elif x > num and y > num:
position(N-1, x - num, y - num, 3 * 4 ** (N - 1) + base)

위와 같이 한 변이 인 영역이 주어졌을 때 각 변을 직각 이등분 하는 선은 가장 좌상단의 꼭짓점에서 만큼 떨어져 있는 것을 확인할 수 있다. 그러므로 x, y가 보다 큰지 작은지 확인하면 네 개의 영역 중 어디에 속해있는지 알 수 있다. 단 여기서 x는 커질수록 오른쪽, y는 커질수록 아래로 진행한다고 생각해야 한다.
Z
백준 1074번 'Z' (실버 1) 문제 풀이. divide and conquer, recursion 로 접근했다.
BOJ10610SILVER 5
nums = str(sys.stdin.readline().strip())
if '0' not in nums:
print(-1)
else:
l = [0] * (int(max(nums)) + 1)
s = ''
sum = 0
for i in nums:
l[int(i)] += 1
for i in range(len(l)-1, 0, -1):
s += str(i) * l[i]
sum += i * l[i]
if sum % 3 == 0: print(int(s) * (10 ** l[0]))
else: print(-1)30
백준 10610번 '30' (실버 5) 문제 풀이. math, string, greedy algorithm 로 접근했다.